assignemnt help!

ok. i have been working on my assignment since morning and i feel tiered and confused.


here is the assignment!
Computers have been used to test students on their ability to solve arithmetic problems. Write a program that will test a student on addition,substraction and multiplication using random integers between 10 and 100. The student has 3 chances to answer the problem correctly. If after 3 chances the answer is still incorrect, the correct answer is displayed. A score is calculated by awarding:
20:41:43
§ 10 points for a correct answer on the first try,
§ 5 points on the second try,
§ 2 points on the third try, and
§ 0 points if all three attempts are wrong.
20:42:03
Your program should have the following features:
20:42:20
§ Input the number of questions from the user.
§ Choose numbers randomly (between 10 and 100)
§ Choose operation randomly (addition, substraction or multiplication)


§ Display the total score earned by the student after each question.
§ Use at least 3 functions other than function main.
(Some grades will be allocated to the efficient choice of functions)





and here is what i have wrote :

#include<iostream.h>
#include<iomanip.h>
#include<stdlib.h>

void addition(){

int result=0;
int points=0;
int counter=0;




int nbr1 = 100 % rand() +10;
int nbr2 = 100 % rand() +10;

cout<<nbr1<<" + "<<nbr2<<" = ";
cin>>result;

if(result == nbr1+nbr2){
cout<<" CORRECT ";
points+=10;
return;
}

if(result !=nbr1+nbr2){
counter++;
cout<<"WRONG TRY AGAIN";
}

if (counter == 1){
points+=5;
}


if (counter == 2){
points+=2;
}


if (counter >= 2){
points=0;
cout<<" WRONG!the anwser is "<<nbr1+nbr2<<endl;
return;
}



}








void substraction(){

int result=0;
int points=0;
int counter=0;

int nbr1 = 100 % rand() +10;
int nbr2 = 100 % rand() +10;

cout<<nbr1<<" - "<<nbr2<<" = ";
cin>>result;

if(result == nbr1-nbr2){
cout<<" CORRECT ";
points+=10;
return;

}

if(result !=nbr1-nbr2){
counter++;
cout<<"WRONG TRY AGAIN";
}

if (counter == 1){
points+=5;
}


if (counter == 2){
points+=2;
}


if (counter >= 2){
points=0;
cout<<" WRONG!the anwser is "<<nbr1-nbr2<<endl;
return;
}


}













void multiplication(){

int result=0;
int points=0;
int counter=0;

int nbr1 = 100 % rand() +10;
int nbr2 = 100 % rand() +10;

cout<<nbr1<<" * "<<nbr2<<" = ";
cin>>result;

if(result == nbr1*nbr2){
cout<<" CORRECT ";
points+=10;
return;

}

if(result !=nbr1*nbr2){
counter++;
cout<<"WRONG TRY AGAIN";
}

if (counter == 1){
points+=5;
}


if (counter == 2){
points+=2;
}


if (counter >= 2){
points=0;
cout<<" WRONG!the anwser is "<<nbr1*nbr2<<endl;
return;
}


}

int main(){


int nbrofquestions = 0;

cin>> nbrofquestions;

for(int i=0;i<=nbrofquestions;i++){
addition();

};



return 0;

}





















any guide line would be much much appreciated! just a little advice on how to proceed

thnaks in advance everyone
This looks very similar to your other question...

Regarding the random function selection aspect of the program; I would be inclined to write something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main() {
	int randomchoice = 3 % rand();			//	Assign random number 1-3
	cout << randomchoice << endl;			//	DEBUG: Check value of random number - remove before submission
	switch(randomchoice){		//	Switchcase on said number
		case 1:
			addition();	//	If 1; addition
			break;
		case 2:
			subtraction(); //	If 2; subtraction
			break;
		case 3:
			multiplication(); //	If 3; multiplication
			break;
		default:
			cout << "ERROR: Input not an integral value from 1-3" << endl;	// Standard output - shouldn't get printed
	}
	return 0;
}


HOWEVER the values don't seem to be random - I can get 110*110 more than 5 times in a row. Maybe it's my syntax; I've never used the rand() function before.

Any idea how that could be fixed?
thank you so much :) that really helped
yes it could be fixed by using srand instead of rand and using time to generate random numbers

thnaks again i submited the assignment on time
Last edited on
Topic archived. No new replies allowed.