Thursday, July 9, 2009

Help in C regarding in filtering?

#include%26lt;stdio.h%26gt;





main()


{


int a=0, b=0, c, d, e;





clrscr();


for (c=1; c%26lt;=10; c++)


{


printf("%d + %d = ", c, c);


scanf("%d",%26amp;d);








e=c+c;








if (d==e)


{





printf("Right!\n");


a++;


}


else


{


printf("Sorry your answer is wrong. The answer is %d\n", e);


b++;


}


}





printf("\nThe total right answer(s) is %d", a);


printf("\nThe total wrong answer(s) is %d", b);


getch();


}





this program add numbers up to 10...


how can i add a filter that will end the program if i type an alphabet ???


tnx C masters!!!

Help in C regarding in filtering?
The scanf() function returns the number of items it was able to match up, so if it returns 0, then it was unable to match the input to a number.





if ( scanf("%d", %26amp;d) == 0 ) {


// not a number, do something


}


No comments:

Post a Comment