number ended by 0

i have to create a simple program for my programming class and mij ide is giving me some errors. The program has to calculate the number of figures entered by a hid ended by a "0"

the code i've written is:

// number of numbers.cpp : Defines the entry point for the console application.
//
// set libraries(specified in the library file)
#include"stdafx.h"
//standards
#define zero 0;
int _tmain(int argc, char *argv[])
{
int iNumber=1, iMax=0, iMax_number=1;
 
//check if ending number is 0
while(iNumber!=zero)
{
printf("give a value ended by %d:\r\n",zero);
scanf("%d",&iNumber);
 
// check if iNumber is not negative
while(iNumber<0)
{
printf("enter a positive number");
scanf("%d",&iNumber);
}
//count the number of figures
if(iNumber==iMax)
{
iMax_number++;
}
 
if(iNumber>iMax)
{
iMax=iNumber;
iMax_number=1;
}
}
//a number is entered so print it
if(iMax>0) 
{
printf("\nThe given number= %d\n",iMax);
printf("the number of figures= %d.\n\n",iMax_number);
}
//no number has been entered
else
{
printf("\nNo numbers are entered!\n");
}
//wait for character from stdio/hid
getch();
return 0;
}

the errors given are:
Error 1 error C2143: syntax error : missing ')' before ';'
Error 2 error C2059: syntax error : ')'

at line 12 & 14

Saxion highschool, Enschede, Netherlands, R.W.H.J. Verbruggen, programming 1

#define zero 0;

Remember that #define does an entirely literal text substitution. It's not anything like a variable or alias.

So you get while(iNumber!=zero) turning into while(iNumber!=0;) which is the wrong place to put a ;

There's no point #define-ing zero since it adds no meaning, not to mention the value of zero will never change. Use #define to declare values you might change, like

#define BUFFER_SIZE 512

...

char buf[BUFFER_SIZE];

to make altering them more convenient later.

1 Like

thank you, worked :stuck_out_tongue: