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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
//declaring.
void Displaymenu();
void Add(int,int);
void Subtract(int,int);
void Multiply(int ,int);
void Divide(double, double);
//rest of code in main() and other function calls are here.
int main()
{
int choice;
string continu = "y";
string username;
//menu choice constants
const int ADD_CHOICE = 1;
const int SUB_CHOICE = 2;
const int MULT_CHOICE = 3;
const int DIV_CHOICE = 4;
const int QUIT_CHOICE = 5;
//setting up output.
cout << fixed << showpoint << setprecision(2);
//prompt user to continue.
cout << "Press y to continue" << endl;
cin >> continu;
// prompt for user name
cout << "Please enter your name " << endl;
cin >> username;
//test for validation.
do
{
//display the menu ask for input.
Displaymenu();
cin >> choice;
//Validate user choice.
while (choice < ADD_CHOICE || choice > QUIT_CHOICE)
{
cout << "Please enter a valid menu choice: " << endl;
cin >> choice;
}
//continue with program if user does not choose to quit.
if (choice !=QUIT_CHOICE)
{
//perform the necessary execution and operations depending on user choice.
switch (choice)
{
case ADD_CHOICE:
Add(add1, add2); // error1 undeclared identifiers add1 and add2
break;
case SUB_CHOICE:
Subtract(sub1, sub2); // error1, sub1 and sub2 undeclared identifiers
break;
case MULT_CHOICE:
Multiply(mut1, mut2); // error1, mut1 and mute same as above
break;
case DIV_CHOICE:
Divide(double div1, double div2); // error 2
break;
}
}
} while (choice!=QUIT_CHOICE);
cout << "good bye" << endl;
return 0;
}
// defining said functions outside of main(),
void Add(int add1, int add2)
{
srand((unsigned)time(0));
add1 = rand() % 100 +1;
add2 = rand() % 100 +1;
cout << "***** ADDITION *******" << endl;
cout << "********************** " << endl;
cout << "***" << add1 << "+" << add2 <<"=" << "?" << "***" << endl;
}
void Subtract(int sub1, int sub2)
{
srand((unsigned)time(0));
sub1 = rand() % 100 +1;
sub2 = rand() % 100 +1;
cout << "****** SUBTRACTION ***** " << endl;
cout << "************************ " << endl;
cout << "***" << sub1 << "-" << sub2 << "=" << "?" << "***" << endl;
}
void Multiply(int mut1, int mut2)
{
srand((unsigned)time(0));
mut1 = rand() % 100 +1;
mut2 = rand() % 100 +1;
cout << "****** MULTIPLICATION *****" << endl;
cout << "***************************" << endl;
cout << "***" << mut1 << "*" << mut2 << "=" << "?" << "***" << endl;
}
void Divide(double div1, double div2) //Expected "(" error here.
{
srand((unsigned)time(0));
div1 = rand() % 100 +1;
div2 = rand() % 100 +1;
cout << "***** DIVISION *******" << endl;
cout << "**********************" << endl;
cout << "***" << div1 << "/" << div2 << "=" << "?" << "***" << endl;
}
void Displaymenu()
{
cout << " 1. ADD " << endl;
cout << " 2. SUBTRACT" << endl;
cout << " 3. MULTIPLY " << endl;
cout << "4. DIVIDE " << endl;
cout << " 5. QUIT " << endl;
cout << " Please select an option between 1-4, select 5 to quit" << endl;
}
|