0

What is the error in this code?

I don't no what's the error in the following code please help me to solve this issue in this code https://code.sololearn.com/caZHsuNy3T5S/?ref=app

5th Sep 2021, 10:02 AM
PUNEETH M
PUNEETH M - avatar
8 Answers
+ 3
You can leave the order the same just place a space before %c to catch the leftover '\n' character in the input stream. scanf(" %c", &op);
5th Sep 2021, 10:55 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Hey PUNEETH M , I am not saying that I made this code correct but you need to understand the behaviour of operator, if else, char and Macro PS: this code is only working for + operator cause I only define + Operator as Macro https://code.sololearn.com/cpuUSX6GY6iF/?ref=app
5th Sep 2021, 11:22 AM
Saurabh
Saurabh - avatar
+ 1
Change void into int void main() to int main() and your code gonna run smoothly
5th Sep 2021, 10:05 AM
Myo Thuzar
Myo Thuzar - avatar
+ 1
Not working bro
5th Sep 2021, 10:12 AM
PUNEETH M
PUNEETH M - avatar
+ 1
PUNEETH M Plz change you code order to printf("Enter the sign of operation:\n "); scanf("%c", &op); // not %s , %c for char printf("Enter the A: \n"); scanf("%d", &a); printf("Enter the B: \n"); scanf("%d", &b); now,it's working. tested!! B.coz your code will work depending on the sign of operation ,so program need to check the sign first,I think
5th Sep 2021, 10:34 AM
Myo Thuzar
Myo Thuzar - avatar
+ 1
ChaoticDawg is right,plz do correct your code like that
5th Sep 2021, 11:00 AM
Myo Thuzar
Myo Thuzar - avatar
0
Thank you so much 💗 . If I give space for %c it's working but I did not understand logic behind the space before %c. Can you explain . Any way thank so much once again for Myo Thuzar and also to Saurabh Kumar Yadav
6th Sep 2021, 9:00 PM
PUNEETH M
PUNEETH M - avatar