#include <stdio.h>
// Begin Main
main ()
{
// Define variables
int num1 = 0;
int num2 = 0;
int result = 0;
int choice = 0;
// Print the menu
printf("Calculator v2.0\n");
printf("------------\n");
printf("1. Add\n");
printf("2. Subtract\n");
printf("3. Multiply\n");
printf("4. Devide\n");
printf("5. Remainder\n");
printf("----------------\n");
printf("Choice:");
scanf("%d" , &choice);
if ((choice >= 1) && (choice <= 5))
// Print : Enter num1
printf("Enter the first number:");
// Read num1
scanf("%d" , &num1);
// Print : Enter num2
printf("Enter the second number:");
//Read num2
scanf("%d", &num2);
if (choice == 1)
{
// Add num1 and num2
result = num1 + num2;
}
else if (choice == 2)
{
// Subtract num1 and num2
result = num1 - num2;
}
else if (choice == 3)
{
// Multiply num1 and num2
result = num1 * num2;
}
else if (choice == 4 )
{
// Devide num1 and num2
result = num1 / num2;
}
else if (choice == 5)
{
// Remainder num1 and num2
result = num1 %num2;
}
//Print : The result
printf("The result is %d\n", result);
else <---- here the programs says to me else without previous if, idk why thought
{
//Print Error message
printf("Please enter a number from 1 to 5!\n");
}
if (choice == 1)
result = num1 + num2;
printf("The result is %d\n", result);
elseif (choice == 2)
result = num1 - num2;
printf("The result is %d\n", result);
elseif (choice == 3)
result = num1 * num2;
printf("The result is %d\n", result);
elseif (choice == 4 )
result = num1 / num2;
printf("The result is %d\n", result);
elseif (choice == 5)
result = num1 %num2;
printf("The result is %d\n", result);
else
printf("Please enter a number from 1 to 5!\n");
//...
//...
bool f=true ;//set flag
if (choice == 1)
{
// Add num1 and num2
result = num1 + num2;
}
elseif (choice == 2)
{
// Subtract num1 and num2
result = num1 - num2;
}
elseif (choice == 3)
{
// Multiply num1 and num2
result = num1 * num2;
}
elseif (choice == 4 )
{
// Devide num1 and num2
result = num1 / num2;
}
elseif (choice == 5)
{
// Remainder num1 and num2
result = num1 %num2;
}
else //<---- here the programs says to me else without previous if, idk why thought
{
//Print Error message
f = false;
printf("Please enter a number from 1 to 5!\n");
}
//Print : The result
if (f) printf("The result is %d\n", result);
return 0;
}