All pastes #815510 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-12-14 03:14 UTC
rendered paste body
int AdditionLawl(int &addition)
/* Displays random addition problems */

{
	int answer;
	int right;
	int tries;
	double score;
	score = 0;

	randomize();

	int n1 = (random(100) + 1);
	int n2 = (random(100) + 1);

	cout << "\n \t" << n1 << " + " << n2 << " = ";
	cin >> answer;

	while((right != 1) || (tries < 3)) {
		if (answer == n1 + n2) {
			right = 1;
			tries = 0;
			cout << "\t" << "CORRECT" << endl;
		}
		else if (answer != n1 + n2) {
				cout << "\t" << "WRONG Try again" << endl;
				cout << "\n \t" << n1 << " + " << n2 << " = ";
					cin >> answer;
					right = 0;
					tries = 1;
			}
		if (answer == n1 + n2) {
			cout << "\t" << "CORRECT" << endl;
			right = 1;
		}
		else if (answer != n1 + n2) {
				cout << "\t" << "WRONG Try again" << endl;
				cout << "\n \t" << n1 << " + " << n2 << " = ";
					cin >> answer;
					right = 0;
					tries = 2;
		}
		if (answer == n1 + n2) {
			cout << "\t" << "CORRECT" << endl;
			right = 1;
		}
		else if (answer != n1 + n2) {
				cout << "\t" << "You've been wrong 3 times. The answer is " << n1 + n2 << endl;
		}
	}

	if (tries == 0) {
		score += 10;
	}
	else if (tries == 1) {
		score +=5;
	}
	else if (tries == 2) {
		score +=2;
	}
		return(answer);
}