our program should present a menu with 4 options,
1) Print author info
2) perform integer operation
3) perform floating point operation
0) Exit
Where selection 1 prints your information (name and student id)
selection two performs an integer math operation
selection 3 performs a floating point (non whole number) math operation.
Selection 0 will exit the program right immediately.
Any other selection will print an error message stating that an invalid selection was made.
When one of the math operation selections are chosen, the user will enter a simple math formula (such as "1+1") you should then calculate the result of their entered formula and print both the operation and the result to the screen.
for example if the user entered:
"4*6"
You would print:
4 * 6 = 24
You can expect the user to enter the formula in the format of:
op1<operand>op2 where there is no white space in the formula.
The operations you must support are:
+ addition
- subtraction
* multiplication
/ division
Make sure your results are mathematically correct.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#include<stdio.h>
#include<math.h>
int main()
{
int ival;
double fval;
int menu;
printf("Press 1 to Author info\nPress 2 perform integer operation\nPress 3 perform floating point operation\nPress 0 to exit\n");
scanf("%d", &menu);
if (menu == 1)
{
printf("Author is \nStudent ID is \n");
}
else if (menu == 2)
{
printf("Please enter an integer operation\n");
{
scanf("%d%c%d\n");
printf("%d%c%d");
}
}
else if (menu == 3)
{
// perform floating point operation
}
else if (menu == 0)
{
//Exit
}
system("pause");
return (0);
}
|