November 14,2013
COP 2000 assignment #4
*/
#include <cstdlib>
#include <iostream>
#include <cmath>
usingnamespace std;
void intRand (int &);
void showMenu();
int main ()
{
float guess, ANS;
int choice;
constint ADD_CHOICE = 1,
SUB_CHOICE = 2,
MULTI_CHOICE = 3,
QUIT_CHOICE = 4;
do
showMenu();
while (choice < ADD_CHOICE || choice > QUIT_CHOICE);
{
cout << "Please enter a valid menu choice: ";
cin >> choice;
}
if (choice != QUIT_CHOICE)
{
cout << "What is your answer? ";
}
cin >> guess;
switch (choice)
{
case 1:
cout << "r1 + r2" << "= ? \n";
cin>> (guess);
if (guess == ANS) cout << "Great job!";
else cout << ANS;
break;
case 2:
cout << ("r1 - r2") << "= ? \n";
cin>> ANS;
if (ANS == guess); cout << "Great job!";
break;
case 3:
cout << ("r1 * r2") << "= ? \n";
cin>> ANS;
if (ANS == "r1 * r2"); cout << "Great job!";
break;
case 4:
exit(0);
return 0;
}
{
void showMenu()
{
cout << "\n\t\tMENU OF OPERATIONS \n\n "
<< " 1. Addition.\n";
<< " 2. Subtraction.\n";
<< "\n 3. Multiplication.\n";
<< "\n 4. Quit the Program.\n\n"
<< " Enter the number of the operation to try (1-4):";
}
void intRand()
{
r1 = rand() % 11 + 2;
r2 = rand() % 11 + 2;
}
}
return 0;
}
I fixed the == error and my other mistakes you listed. I am still getting these errors.
59 12 [Error] invalid operands of types 'float' and 'const char [8]' to binary
'operator=='
71 4 [Error] a function-definition is not allowed here before '{' token
/*
November 14,2013
COP 2000 assignment #4
*/
#include <cstdlib>
#include <iostream>
#include <ctime>
usingnamespace std;
void intRand (int *);
void showMenu();
int main ()
{
float guess, ANS;
int r[2];
int choice = 0;
int ADD_CHOICE = 1,
QUIT_CHOICE = 4;
srand((unsignedint)time((time_t *)NULL));//need for rand()
showMenu();
while (choice < ADD_CHOICE || choice > QUIT_CHOICE)
{
cout << "Please enter a valid menu choice: ";
cin >> choice;
}
if (choice == QUIT_CHOICE)
return 0;
cout << "What is your answer for ";
intRand(r);
// cout << r[0] << " " << r[1] << '\n'; // test if rand() works
switch (choice)
{
case 1:
ANS = r[0] + r[1];
cout << "r1 + r2" << "= ? ";
cin>> guess;
if (guess == ANS)
cout << "Great job!";
else
cout << ANS << '\n';
break;
case 2:
ANS = r[0] - r[1];
cout << ("r1 - r2") << "= ? ";
cin>> guess;
if (ANS == guess)
cout << "Great job!";
else
cout << ANS << '\n';
break;
case 3:
ANS = r[0] * r[1];
cout << ("r1 * r2") << "= ? ";
cin>> guess;
if (ANS == guess)
cout << "Great job!";
else
cout << ANS << '\n';
break;
}
return 0;
}
void showMenu()
{
cout << "\n\t\tMENU OF OPERATIONS \n\n"
<< " 1. Addition.\n"
<< "\n 2. Subtraction.\n"
<< "\n 3. Multiplication.\n"
<< "\n 4. Quit the Program.\n\n";
}
void intRand(int *r)
{
r[0] = rand() % 11 + 2;
r[1] = rand() % 11 + 2;
}
MENU OF OPERATIONS
1. Addition.
2. Subtraction.
3. Multiplication.
4. Quit the Program.
Please enter a valid menu choice: 1
What is your answer for r1 + r2= ? 12
16