Mar 22, 2015 at 2:20pm UTC
Hi guys!
Whats wrong with my code?
I got this 2 lines at same time and not 1 at a time.
Sorry for my english.
Digite uma operacao:
Digite outro numero:
This code is supposed to read 2 number and a logical operation (+, -, /, *) and print the result depending on the logical operation choosen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int num1, num2;
char op[1];
double total;
printf("Digite um numero: " );
scanf_s("%d" , &num1);
printf("\nDigite uma operacao: " );
scanf_s(op);
printf("\nDigite outro numero: " );
scanf_s("%d" , &num2);
if (strcmp(op, "+" ) == 0) {
total = (num1 + num2);
}
else if (strcmp(op, "-" ) == 0) {
total = (num1 - num2);
}
else if (strcmp(op, "*" ) == 0) {
total = (num1 * num2);
}
else if (strcmp(op, "/" ) == 0) {
total = (num1 / num2);
}
printf_s("%.2f" , &total);
system("pause>>null" );
}
Last edited on Mar 22, 2015 at 2:31pm UTC