simple calculator: what's wrong with this code?
Pls help
Thank you
Code:
/* A simple program in which the user picks 2 numbers and does mathematical operation ( +, -, * or / ) */
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num1;
int num2;
int rsult = 0;
char oprtn;
printf("Enter the first number: ");
scanf("%i", &num1);
printf("Enter the second number: ");
scanf("%i", &num2);
printf("Choose an operator (a/s/m/d): ");
scanf("%s", &oprtn);
switch(oprtn)
{
case 'a':
rsult = num1 + num2;
printf("Your result is %i", rsult);
break;
case 's':
rsult = num1 - num2;
printf("Your result is %i", rsult);
break;
case 'm':
rsult = num1 * num2;
printf("Your result is %i", rsult);
break;
case 'd':
rsult = num1 / num2;
printf("Your result is %i", rsult);
break;
}
getch();
}
test:
num1 = 5
num2 = 6
oprtn = a
gives a result of 5