
Originally Posted by
zer0_r00t
Edit:
Code:
/* A simple program in which the user picks 2 numbers and does mathematical operation ( +, -, * or / ) */
#include <stdio.h>
#include <stdlib.h>
<SNIP>
No errors, no warnings

Here's how I made it work in code::blocks:
Code:
/* A simple program in which the user picks 2 numbers and does mathematical operation ( +, -, * or / ) */
#include <stdio.h> //this is all you need for your code, getchar is included
int main(void)
{
int x, y;
float a, b;
int result = 0;
float divresult = 0.00; //just a habit of mine
int operation;
printf("Enter the first number: ");
scanf("%d", &x); //using recommended %d instead of %i
printf("Enter the second number: ");
scanf("%d", &y);
printf("Choose an operator\n");
printf("1 = add, 2 = subtract, 3 = multiply, 4 = divide\n"); //more attractive to user
scanf("%d", &operation); //float is only needed for result, not integer input
switch(operation)
{
case 1:
result = x+y;
printf("Your result is %d", result); //seemed simpler to include result line
break; //in every case instead of trying to
//trying to sort it out outside of switch
case 2:
result = x-y;
printf("Your result is %d", result);
break;
case 3:
result = x*y;
printf("Your result is %d", result);
break;
case 4:
a = (float) x; //recasting results to float for division
b = (float) y; //recasting results to float for division
divresult = a/b;
printf("Your result is %f", divresult);
break;
default:
printf("You made a boo-boo. Run program again.");
}
getchar(); //I assume you wished to pause console program before exit
return 0;
}