Ask your own question, for FREE!
Computer Science 25 Online
OpenStudy (anonymous):

Can some one debug it pls.. #include int main() { int one,two,ans=0; char sym; printf("Enter a number: "); scanf("%d/n",&"%d/n",&one); printf("Enter another number :"); scanf("%d/n",&two); printf("Enter an operator(+,-,*,/): "); scanf("%ch/n",&sym); if(sym=='+') ans=one+two; else if(sym=='-') ans=one-two; else if(sym=='*') ans=one*two; else ans=one/two; printf("The result is: ",ans); getch(); return 0; } It always show same result i.e -7188

OpenStudy (anonymous):

scanf("%d\n", &"%d\n", $one); is this a typo?

OpenStudy (anonymous):

also scanf("%ch\n", &sym); %c is the correct conversion specifier and not %ch :-(

OpenStudy (anonymous):

instead of that line, you can use sym = getchar()

OpenStudy (anonymous):

Finally, you've got printf("The result is: ", ans) with no %d conversion specifier in the format string.

OpenStudy (anonymous):

C is a lot complicated than C++. :P

OpenStudy (anonymous):

not really. It's just that scanf() is so inconvenient

OpenStudy (anonymous):

now it shows 4+4=1

OpenStudy (anonymous):

http://ideone.com/bTFbT

OpenStudy (anonymous):

hahaha I have a bug in there: one / 2 instead of one / two :-P

OpenStudy (anonymous):

http://ideone.com/xCtvs

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!