1. ## Calculator code help

I just started doing the C tutorials yesterday and decided to apply the little i have learnt. My calculator is supposed to take an input for two numbers, then it has to print a menu whit four mathematical operations and takes input of the operation selected. If conditions apply to each operation. After that has been done the result of the operation is supposed to be printed. The code complies with no errors but after the second number has been inputed it prints the menu and the result. Here is my code and any sort of help will be greatly appreciated. Thank You
Code:
```#include <stdio.h>

int main()
{
/*Author: Morpheous 11
14th December 2008 */

double firstNum;
double secNum;
double result;
char operationSelected;

scanf("%lf",&firstNum);
scanf("%lf",&secNum);

printf("subtraction(-)\n");
printf("multiplication(*)\n");
printf("division(/)\n");

scanf("%c",&operationSelected);

if (operationSelected == '+')
{
result = firstNum + secNum;
}// end of if statement for addition

else if (operationSelected == '-')
{
result = secNum - firstNum;
}// end of if statement for subtraction

else if (operationSelected == '*')
{
result = firstNum * secNum;
}// end of if statement for multiplication

else if (operationSelected == '/')
{
result = firstNum / secNum;
}// end of if statement for division

else
printf("Enter a valid operation");

printf("The result is %lf",result);
getchar();
return 0;
}// end of main```

2. Your code looks good in the code tags.

Your written description is so poor, I can't help but giggle through my pain of trying to decipher WTF you're trying to say. You can do better than this!

Please post an input that shows the wrong output, and post that wrong output, as well.

Don't get nervous or distracted. Just write it up, like you would say it, if you were talking to us.

We pretty much have it figured out that all programs need to actually print out a result, so no need to belabor the obvious, please.

And welcome to the forum. Don't take anything I post, personally - it's not meant that way.

Oh! One problem is easy to spot - you're not pulling the newline off the keyboard's buffer.

With scanf(), it leaves the '\n' (newline), behind. That goofs up the next scanf().

You need one of these after every scanf(), except the last one:

garbage = getchar();

to pull the newline off. I use "gar" for short, but any function that pulls a char off the keyboard buffer (stdin), will do fine.

3. thank you

4. Modified it lil bit id hope it could help.
Code:
```#include <stdio.h>

int main()
{
/*Author: Morpheous 11
14th December 2008 *
*modifed By LOLGUY*/

double firstNum;
double secNum;
double result;
int operationSelected;

scanf("&#37;lf",&firstNum);
scanf("%lf",&secNum);

puts("subtraction(2)");
puts("multiplication(3)");
puts("division(4)");

scanf("%d",&operationSelected);
switch(operationSelected)
{
case 1 :
result = firstNum + secNum;
break;
case 2:
result=secNum - firstNum ;
break;

case 3:
result = firstNum * secNum;break;
case 4:
result = firstNum / secNum;break;

}

printf("The result is %lf",result);
getchar();
return 0;
}```

5. thank you for your help. I decided to use if statements becuase i dont know how to char the switch to take characters.