I should write a program for simple calculator that does addition,subtraction,multiplication,division and module.
It should work like that :ask user to enter expression and the echo back user expression(removing all spaces ) with the correct answer.
we can only use getchar, putchar, no arrays, no scanf for the calculations. printf is ok.
It is kind of impossible program for me.
so this program continously loops around the first if statement never processing the rest of the information.. how do i stop it and allow it to run the actualy calculation.
the user is supposed to put in " 3 + 5" and then the program outputs "3 + 5 = 8"
BUT IT DOESNT it just echoe's back what i put in. " 3 + 5 "
Thanks.
Firstly, without proper indentation code is hard to read. You should fix that.
Your first problem is the continue on line 19. It says "if char is not a space, do nothing", which is not what you want. You should put the continue in an else statement.
Also the or in the if is wrong. No char is both space and tab, so this is always true. It should be &&.
Your code still wont work right, though.
Try to figure it out.
I think you should have ch = getchar(); before line 27.
EDIT: You should also try to use ungetc with stdin where necessary. For example, you should perform ungetc(ch, stdin) before returning from Convert. This way you wont loose the operation symbol that may follow immediately after a number.