1. //@Author Damien Bell
2. #include <iostream>
3. #include <cmath>
4. using namespace std;
6. void doCalcs(int, double, double);
7.
8. int main(){
9. int choice=0;
10. double x=0, y=0, product=0;
11. char quit =' ';
12. while (quit != 'y'){
14. cin >> choice;
15.
16. cout <<"\nEnter a value for the first number: ";
17. cin >> x;
18.
19. cout <<"\nEnter a value for the second number: ";
20. cin >> y;
21.
22. doCalcs(choice, x, y);
23.
24.
25.
26. cout <<"\nDo you want to quit? y/n ";
27. cin >>quit;
28. }
29. return 0;
30. }
31.
33. cout << "Press 1 to add" <<endl << "Press 2 to subtract" <<endl <<"Press 3 to multiply"<<endl;
34. cout << "Press 4 to divide" <<endl << "Press 5 to raise a number to a power" <<endl <<"Press 6 to mod a number"<<endl;
35. cout << "Please enter your choice: ";
36. }//End function displayMenu
37.
38. void doCalcs(int menuChoice, double a, double b){
40. case 1:{
41. cout << a << " + " << b << " = " <<a+b;
42. }
43. case 2:{
44. cout << a << " - " << b << " = " <<a-b;
45. break;
46. }
47. case 3:{
48. cout << a << " * " << b << " = " <<a*b;
49. break;
50. }
51. case 4:{
52. cout << a << " / " << b << " = " <<a/b;
53. break;
54. }
55. case 5:{
56. cout << a << " ^ " << b << " = " << pow(a, b);
57. break;
58. }
59. case 6:{
60. cout << a << " % " << b << " = " << fmodf(a,b);
61. break;
62. }
63. default:{
64. cout << "Something broke";
65. }
66.
67.
68.
69.
70.
71.
72. }//end switch
73.
74.
75. }//end function doCalc
76.
77.
78.
Success #stdin compilation error #stdout 0s 2864KB
stdin
5
2
4
y
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:10: warning: unused variable ‘product’
stdout
Press 1 to add
Press 2 to subtract
Press 3 to multiply
Press 4 to divide
Press 5 to raise a number to a power
Press 6 to mod a number