I am writing a program that generates 2 random #'s then asks the user to give the product of the 2. I have everything (close to) working except the input. I even added a "cheat" to display the answer prod and when inputting the exact same #, it is registering as incorrect.

Thanks for your help, this is due in like an hour so I am trying to finish it up.

int main ()
{
	int a, wrong, right;
	int count = 0;
	int count2 = 0;
	int num1, num2, prod;
	srand (time(0));
	wrong = 0;
	right = 0;
	cout << "Multiplication\n" << "ctrl-z to quit\n";

	while (count <= 11)
	{
		count++;
		if (count >= 10)
		{
			count2 = count2 + count;
			count = 0;
		}

		randomGen (&num1, &num2);
		prod = num1 * num2;
		cout << "What is " << num1 << " times " << num2 << endl;
		cin >> a;
		counter (&count, &count2, &wrong, &right);

		while (!cin.eof() || a != prod)
		{
			cout << prod;
			incorrect ();	
			wrong++;
			cin >> a;
		}

		if (a == prod)
		{
			correct();
			right++;
		}
		
	}
	
}

here is the rest of the code, I just posted the relevant sections. That's why you got the errors.

Thanks

int randomGen (int *num1, int *num2)
{
	*num1 = rand () % 10;
	*num2 = rand () % 10;
	return *num1, *num2;
}

void correct()
{
	int x;
	srand (time(0));
	x = rand () % 5;

	switch (x)
	{
		case 1:
			cout << "\nGreat!" << endl;
			break;
		case 2:
			cout << "\nCorrect!" << endl;
			break;
		case 3:
			cout << "\nYou got it!" << endl;
			break;
		case 4:
			cout << "\nGood job" << endl;
			break;
		case 5:
			cout << "\nYay!" << endl;
	}
}


void incorrect()
{
	int x;
	srand (time(0));
	x = rand () % 5;

	switch (x)
	{
		case 0:
		case 1:
			cout << "\nWrong!" << endl;
			break;
		case 2:
			cout << "\nNo!" << endl;
			break;
		case 3:
			cout << "\nDunce!" << endl;
			break;
		case 4:
			cout << "\nGive it another shot" << endl;
			break;
		case 5:
			cout << "\nOops!" << endl;
	}
}
void counter (int *count, int *count2, int *wrong, int *right)
{
	if (*count2 >= 10 && *count2 % 10 == 0)
		{
			cout << setw(10) << "Wrong " << setw(10) << " Right " << setw(10) << " Total\n"
				 << setw(10) << *wrong << setw(10) << *right << setw(10) << *wrong + *right << endl;
		}
}
while (!cin.eof() || a != prod)

will continue as long as the user has not hit ctrl-z OR has a wrong answer. try using AND

remember that the modulus operator (%) will give results in the range 0-(divisor -1) - check your switches, and the values you are generating for the multiplicands.

srand( ) need only be called once in your program - main( ) should call it early on.

your outer while loop should also check for eof( ) for the program to end correctly.

that should be enough to keep you busy for a while.

Val

This question has already been answered. Start a new discussion instead.