When I compile this, is gives me this error: C:\Documents and Settings\Brandon\Desktop\C++ Folder\final\Cpp1.cpp(38) : error C2297: '%' : illegal, right operand has type 'double' . I have the error commented below inside of the int GetRandomNumber() function, but I simpy have no idea how to fix it. Any help will be greatly appreciated.
Code:
#include <iostream.h>
#include <iomanip.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
int GetRandomNumber();
void ProgramDescription();
void Menu();
void Addition();
void Subtraction();
void Multiplication();
void CorrectResponse(int t);
void AskPlayAgain(bool & play);
const double low = -20;
const double high = 20;
const int LOOP_LIMIT = 10;
void main()
{
bool play;
srand(time(0));
ProgramDescription();
do{
Menu();
AskPlayAgain(play);
}while (play==true);
}
//ERROR
int GetRandomNumber()
{
srand(time(0));
//ERROR IS HERE
return low + rand()%(high - low + 1);
}
void ProgramDescription()
{
cout << "This program will give a student ten questions of their choice:\n";
cout << "Addition, Subtraction, and Multiplication.\n";
cout << "Welcome to the Math Wizard.";
}
void Menu()
{
int option;
cout << "Menu\n";
cout << "----\n";
cout << "1 - Addition\n";
cout << "2 - Subtraction\n";
cout << "3 - Multiplication\n";
cin >> option;
while (option != 1 && option != 2 && option != 3)
{
cout << "Please pick option 1 - 3.\n";
}
if (option == 1)
{
Addition();
}
else if (option == 2)
{
Subtraction();
}
else if (option == 3)
{
Multiplication();
}
}
void Addition()
{
int response;
int numbers;
int something;
int answer;
int number_1;
int number_2;
int counter;
for (numbers = 1; numbers = LOOP_LIMIT; numbers = counter + 1)
{
number_1 = GetRandomNumber();
number_2 = GetRandomNumber();
answer = number_1 + number_2;
cout << number_1 << " + " << number_2 << " = ";
cin >> response;
srand(time(0));
while (response != answer)
{
something = 1 + rand() % (4 - 1 + 1);
switch (something)
{
case 1 : cout << "Nope, try again.\n";
break;
case 2 : cout << "That is incorrect.\n";
break;
case 3 : cout << "Not quite.\n";
break;
case 4 : cout << "Come on you can do it.\n";
break;
}
cout << "Please try again.\n";
cin >> response;
}
if(response == answer)
{
something = 1 + rand() % (4-1+1);
switch (something)
{
case 1 : cout << "Good Job!\n";
break;
case 2 : cout << "Excellent!\n";
break;
case 3 : cout << "Very Good!\n";
break;
case 4 : cout << "Your're Good!\n";
break;
}
cout << "You're ready for the next one.\n";
}
}
}
void Subtraction()
{
int response;
int numbers;
int something;
int answer;
int number_1;
int number_2;
int counter;
for (numbers = 1; numbers = LOOP_LIMIT; numbers = counter + 1)
{
number_1 = GetRandomNumber();
number_2 = GetRandomNumber();
answer = number_1 - number_2;
cout << number_1 << " - " << number_2 << " = ";
cin >> response;
srand(time(0));
while (response != answer)
{
something = 1 + rand() % (4 - 1 + 1);
switch (something)
{
case 1 : cout << "Nope, try again.\n";
break;
case 2 : cout << "That is incorrect.\n";
break;
case 3 : cout << "Not quite.\n";
break;
case 4 : cout << "Come on you can do it.\n";
break;
}
cout << "Please try again.\n";
cin >> response;
}
if(response == answer)
{
something = 1 + rand() % (4-1+1);
switch (something)
{
case 1 : cout << "Good Job!\n";
break;
case 2 : cout << "Excellent!\n";
break;
case 3 : cout << "Very Good!\n";
break;
case 4 : cout << "Your're Good!\n";
break;
}
cout << "You're ready for the next one.\n";
}
}
}
void Multiplication()
{
int response;
int numbers;
int something;
int answer;
int number_1;
int number_2;
int counter;
for (numbers = 1; numbers = LOOP_LIMIT; numbers = counter + 1)
{
number_1 = GetRandomNumber();
number_2 = GetRandomNumber();
answer = number_1 * number_2;
cout << number_1 << " * " << number_2 << " = ";
cin >> response;
srand(time(0));
while (response != answer)
{
something = 1 + rand() % (4 - 1 + 1);
switch (something)
{
case 1 : cout << "Nope, try again.\n";
break;
case 2 : cout << "That is incorrect.\n";
break;
case 3 : cout << "Not quite.\n";
break;
case 4 : cout << "Come on you can do it.\n";
break;
}
cout << "Please try again.\n";
cin >> response;
}
if(response == answer)
{
something = 1 + rand() % (4-1+1);
switch (something)
{
case 1 : cout << "Good Job!\n";
break;
case 2 : cout << "Excellent!\n";
break;
case 3 : cout << "Very Good!\n";
break;
case 4 : cout << "Your're Good!\n";
break;
}
cout << "You're ready for the next one.\n";
}
}
}
void AsPlayAgain(bool & play)
{
char response;
cout << "Do you want more problems? (y or n)";
cin >> response;
while (response != 'y' && response != 'Y' && response != 'n' && response != 'N')
{
cout << "Please enter y or n.";
cin >> response;
}
if (response == 'y' || response == 'Y')
{
play = true;
}
else
{
play = false;
}
}