User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 455,968 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,746 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 533 | Replies: 3 | Solved
Reply
Join Date: Nov 2007
Posts: 21
Reputation: picklesandmayo is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
picklesandmayo picklesandmayo is offline Offline
Newbie Poster

Help Program does not recognize actual input = expected output

  #1  
Nov 26th, 2007
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++;
		}
		
	}
	
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Posts: 21
Reputation: picklesandmayo is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
picklesandmayo picklesandmayo is offline Offline
Newbie Poster

Re: Program does not recognize actual input = expected output

  #2  
Nov 26th, 2007
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;
		}
}
Reply With Quote  
Join Date: Nov 2007
Posts: 21
Reputation: picklesandmayo is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
picklesandmayo picklesandmayo is offline Offline
Newbie Poster

Re: Program does not recognize actual input = expected output

  #3  
Nov 26th, 2007
I figured it out, it is because I have while (!cin.oef
Reply With Quote  
Join Date: Aug 2007
Location: South Dakota
Posts: 980
Reputation: vmanes is a jewel in the rough vmanes is a jewel in the rough vmanes is a jewel in the rough vmanes is a jewel in the rough 
Rep Power: 6
Solved Threads: 97
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Shark

Re: Program does not recognize actual input = expected output

  #4  
Nov 26th, 2007
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
I am in mourning for my country.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 9:08 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC