I have a problem with a calculator i was making. I could use some help because i get the following error:
calculator.c: In function ‘main’:
calculator.c:14: error: ‘a’ undeclared (first use in this function)
calculator.c:14: error: (Each undeclared identifier is reported only once
calculator.c:14: error: for each function it appears in.)
calculator.c:24: error: ‘s’ undeclared (first use in this function)
calculator.c:34: error: ‘m’ undeclared (first use in this function)
calculator.c:44: error: ‘d’ undeclared (first use in this function)
here is the code:
Code:
#include <stdio.h>
int main ()
{
char letter;
int num1;
int num2;
int answer;
printf("Enter <a> for addition \nEnter <s> for subtraction \nEnter <m> for multiplication \nEnter <d> for division \nEnter:");
scanf("%c", &letter);
if (letter == a)
{
printf("Enter the two numbers you want to add");
scanf("%d", &num1);
scanf("%d", &num2);
answer = num1+num2;
printf("The answer is:%d", answer);
}
else if (letter == s)
{
printf("Enter the two numbers you want to subtract");
scanf("%d", &num1);
scanf("%d", &num2);
answer = num1-num2;
printf("The answer is:%d", answer);
}
else if (letter == m)
{
printf("Enter the two numbers you want to multiply");
scanf("%d", &num1);
scanf("%d", &num2);
answer = num1*num2;
printf("The answer is:%d", answer);
}
else if (letter == d)
{
printf("Enter the two numbers you want to divide");
scanf("%d", &num1);
scanf("%d", &num2);
answer = num1/num2;
printf("The answer is:%d", answer);
}
else
{
printf("Please Try again");
}
return 0;
}
Could someone give me a hand please?