I need to create a calculator that will read the operator first followed by a space the first number and then another space the second number. So the user input should look like this
+ 8 8
then output it like this
8 + 8 = 16
This is what i have so far, I was wondering if i was on the right track and if not some tips please.
insert
Code:
#Include <stdio>
void main (void){
int sum, num1, num2, i;
double symbol;
printf("Enter Operator, Number 1, Number 2:\n");
scanf("%d",&symbol, &num1, &num2);
if (symbol = * ) {
for (i = 0; i < num1 ; i++){
sum = sum + num2;
}
printf("%d", num1, * , num2, = , sum);
}
else if (symbol = -){
num1 - num2 = sum;
printf("%d", num1, - , num2, =, sum);
}
else if (symbol = +){
num1 + num2 = sum;
printf("%d", num1, +, num2, =, sum);
}
else{
printf("Selection is Invalid");