Help with simple code pls!

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
The answer to your question depends on what is the code supposed to do?
Please give a description of what you are expecting the program to accomplish, and describe what the program is doing currently that deviates from your expectations.

How to ask questions the smart way:
http://www.catb.org/~esr/faqs/smart-questions.html
Topic archived. No new replies allowed.