I am trying to write a program that is able to read two real numbers followed by a character which is inputted by the user. Then the program will evaluate the two numbers by the character. The character can be any of the ones that I have listed below:
1. + (addition)
2. - (subtraction)
3. * (multiplication)
4. / (division)
5. % (remainder)
Below I have posted a few lines of code that I have written just to check if the values printed out are correct:
#include<stdio.h>
int main(){
int a,b;
char op;
printf("Enter two real numbers followed by one these characters:+, -, *, /, or % : ");
scanf("%d%d %c",&a,&b,&op);
printf("%d %c %d",a,b,op);
return 0;
}
When I run the program the output is not what I expected.
If anyone can explain why I see different values that would be greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire