Need some help with using one function multiple times with different return

hi guys thanks for viewing and helping me out!!

here is the example what the result should looks like

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
    Enter problems per set: 3    

    Set #1
   
    What is the maximum number for this set? 100    

    45 + 21 = 66
    correct
    0 + 100 = 100    
    correct
    54 + 23 = 67
    incorrect
    
    Set #2
    ----------
    What is the maximum number for this set? 90

    59 - 19 = 40
    correct
    19 - 84 = -29    
    incorrect
    0 - 65 = -65
    correct

    Set #3
    ----------
    What is the maximum number for this set? 20
    0 * 18 = 0
    correct
    15 * 4 = 398
    incorrect
    8 * 17 = 873
    incorrect

    Set#1:  You got 2 correct out of 3 for 66.7%
    Set#2:  You got 2 correct out of 3 for 66.7%
    Set#3:  You got 1 correct out of 3 for 33.3%
    Overall you got 5 correct out of 9 for 55.6%


so far i got the all the thing work without last part which is
Set#1: You got 2 correct out of 3 for 66.7%
Set#2: You got 2 correct out of 3 for 66.7%
Set#3: You got 1 correct out of 3 for 33.3%
Overall you got 5 correct out of 9 for 55.6%
this section

i have no clue how the f... i can get track of the percentages

THE MOST IMPORTANT announcement is that we have to have fixed main code
which is
1
2
3
4
5
6
7
8
9
10
11
    int main()
    {
        <variable declarations>
        
        srand(static_cast<unsigned>(time(0)));    
        getProbsPerSet(<arguments>);  
        doOneSet(<no-more-than-3-arguments>);    
        doOneSet(<no-more-than-3-arguments>);
        doOneSet(<no-more-than-3-arguments>);
        printReport(<arguments>);
    }


here's some code that i made so far
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
using namespace std;

void getProbsPerSet(int&); // let user choose how many time probs
void getMaxNum(int&); // let user choose randome number of maximun value
void printReport(int, int, int);
void doOneSet(char, int); // do one set of each problem
void doOneProblem(int&); // ask user the answer
void checkAnswer(int, int, int&); // compare the answer if it's right
void generateOperands(char&); // declare which calculation it needs
void CalculateCorrectAnswer(int, int, char, int&); // Find correct answer

int main() {
	int probsPerSet;

	getProbsPerSet(probsPerSet); // calling out getProbsPerSet
	srand(static_cast<unsigned>(time(0))); // generate randome number
	doOneSet('+', probsPerSet); // calling out doOneSet with character +
	doOneSet('-', probsPerSet); // calling out doOneSet with character -
	doOneSet('*', probsPerSet); // calling out doOneSet with character *

	system("pause");
	return 0;
}

void getMaxNum(int& Max) {
	cout << "What is the maximum number for this set ? ";
	cin >> Max;
	cout << endl;
}

void printReport(int Max, int Num, int Percent) {

}

void   getProbsPerSet(int &Many) {  // Many will have fixed value now
	cout << "Enter problems per set: ";
	cin >> Many; // return Many as typed value
}

void doOneSet(char Function, int Many) {  // catches int Many, char Function from follwing than do doOneset
	int i;

	if (Function == '+') { // if when char +

		cout << "Set #1" << endl << "----------" << endl;

		int Randome;
		getMaxNum(Randome); // make user choose with max randome number

		for (i = 0; i < Many; i++) { // repeat with following Many
			int First, Second, Answer, Final, Number;
			cout << "Q" << i + 1 << ") ";
			First = rand() % Randome; // generate randome number under what use choose
			Second = rand() % Randome; // generate randome number under what use choose
			cout << First;  // show first generated number
			generateOperands(Function); // show which function we are in
			cout << Second << " = ";  // show second function and =
			doOneProblem(Answer); // ask for user to put value as answer
			CalculateCorrectAnswer(First, Second, Function, Final); // get the correct answer
			checkAnswer(Answer, Final, Number); // compare with use's answer and right answer and show if it's right or wrong
		}
	}
	if (Function == '-') {  // if when char -
		
		cout << "Set #2" << endl << "----------" << endl;

		int Randome;
		getMaxNum(Randome);  // make user choose with max randome number

		for (i = 0; i < Many; i++) { // repeat with following Many
			int First, Second, Answer, Final, Number;
			First = rand() % Randome; // generate randome number under what use choose
			Second = rand() % Randome; // generate randome number under what use choose
			cout << First;  // show first generated number
			generateOperands(Function); // show which function we are in
			cout << Second << " = ";  // show second function and =
			doOneProblem(Answer); // ask for user to put value as answer
			CalculateCorrectAnswer(First, Second, Function, Final); // get the correct answer
			checkAnswer(Answer, Final, Number); // compare with use's answer and right answer and show if it's right or wrong
		}
	}


	if (Function == '*') { // if when char *

		cout << "Set #3" << endl << "----------" << endl;

		int Randome;
		getMaxNum(Randome);  // make user choose with max randome number

		for (i = 0; i < Many; i++) {  // repeat with following Many
			int First, Second, Answer, Final, Number;
			First = rand() % Randome; // generate randome number under what use choose
			Second = rand() % Randome; // generate randome number under what use choose
			cout << First;  // show first generated number
			generateOperands(Function); // show which function we are in
			cout << Second << " = ";  // show second function and =
			doOneProblem(Answer); // ask for user to put value as answer
			CalculateCorrectAnswer(First, Second, Function, Final); // get the correct answer
			checkAnswer(Answer, Final, Number); // compare with use's answer and right answer and show if it's right or wrong
		}
	}
}

void doOneProblem(int& Ans) {
	cin >> Ans;
}

void CalculateCorrectAnswer(int X, int Y, char F, int& A) { // generate correct answer with givin value X,Y with given function F than return A
	if (F == '+') {
		A = X + Y;
	}
	if (F == '-') {
		A = X - Y;
	}
	if (F == '*') {
		A = X * Y;
	}
}

void checkAnswer(int Ans, int A, int &Num) { //compare right answer than user's answer than answer if it's right or wrong

	if (Ans == A) {
		cout << "Correct" << endl;
		Num++;
	}
	else {
		cout << "Incorrect" << endl;
	}
}

void generateOperands(char& F) { // just little trick for generate fixed function
	cout << " " << F << " ";
}


so, what should i do with "void checkAnswer(int, int, int&); "
Hi,

Could we ask you not to do duplicate posts :+)

If this is a re-write of your earlier question, then at least put a link to this Topic in the other one, with an explanation.

The trouble is, people reply not realising the other Topic exists, then the same comments are made, thereby wasting the respondents time.

Cheers
i know i have to do something with return but i'm not sure how and where to put
designed basic idea like this but not quit sure where to start
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
using namespace std;

void getProbsPerSet(int&); // let user choose how many time probs
void getMaxNum(int&); // let user choose randome number of maximun value
void printReport(int, int, int);
void doOneSet(char, int, int&); // do one set of each problem
void doOneProblem(int&); // ask user the answer
void checkAnswer(int, int, int&); // compare the answer if it's right
void generateOperands(char&); // declare which calculation it needs
void CalculateCorrectAnswer(int, int, char, int&); // Find correct answer

int main() {
	int probsPerSet,rightnum;

	getProbsPerSet(probsPerSet); // calling out getProbsPerSet
	srand(static_cast<unsigned>(time(0))); // generate randome number
	doOneSet('+', probsPerSet, rightnum); // calling out doOneSet with character +
	doOneSet('-', probsPerSet, rightnum); // calling out doOneSet with character -
	doOneSet('*', probsPerSet, rightnum); // calling out doOneSet with character *

	system("pause");
	return 0;
}

void getMaxNum(int& Max) {
	cout << "What is the maximum number for this set ? ";
	cin >> Max;
	cout << endl;
}

void printReport(int Max, int Num, int Right) {

}

void   getProbsPerSet(int &Many) {  // Many will have fixed value now
	cout << "Enter problems per set: ";
	cin >> Many; // return Many as typed value
}

void doOneSet(char Function, int Many, int &Right) {  // catches int Many, char Function from follwing than do doOneset
	int i;

	if (Function == '+') { // if when char +

		cout << "Set #1" << endl << "----------" << endl;

		int Randome;
		getMaxNum(Randome); // make user choose with max randome number

		for (i = 0; i < Many; i++) { // repeat with following Many
			int First, Second, Answer, Final, Number;
			cout << "Q" << i + 1 << ") ";
			First = rand() % Randome; // generate randome number under what use choose
			Second = rand() % Randome; // generate randome number under what use choose
			cout << First;  // show first generated number
			generateOperands(Function); // show which function we are in
			cout << Second << " = ";  // show second function and =
			doOneProblem(Answer); // ask for user to put value as answer
			CalculateCorrectAnswer(First, Second, Function, Final); // get the correct answer
			checkAnswer(Answer, Final, Number); // compare with use's answer and right answer and show if it's right or wrong
		}
	}
	if (Function == '-') {  // if when char -
		
		cout << "Set #2" << endl << "----------" << endl;

		int Randome;
		getMaxNum(Randome);  // make user choose with max randome number

		for (i = 0; i < Many; i++) { // repeat with following Many
			int First, Second, Answer, Final, Number;
			First = rand() % Randome; // generate randome number under what use choose
			Second = rand() % Randome; // generate randome number under what use choose
			cout << First;  // show first generated number
			generateOperands(Function); // show which function we are in
			cout << Second << " = ";  // show second function and =
			doOneProblem(Answer); // ask for user to put value as answer
			CalculateCorrectAnswer(First, Second, Function, Final); // get the correct answer
			checkAnswer(Answer, Final, Number); // compare with use's answer and right answer and show if it's right or wrong
		}
	}


	if (Function == '*') { // if when char *

		cout << "Set #3" << endl << "----------" << endl;

		int Randome;
		getMaxNum(Randome);  // make user choose with max randome number

		for (i = 0; i < Many; i++) {  // repeat with following Many
			int First, Second, Answer, Final, Number;
			First = rand() % Randome; // generate randome number under what use choose
			Second = rand() % Randome; // generate randome number under what use choose
			cout << First;  // show first generated number
			generateOperands(Function); // show which function we are in
			cout << Second << " = ";  // show second function and =
			doOneProblem(Answer); // ask for user to put value as answer
			CalculateCorrectAnswer(First, Second, Function, Final); // get the correct answer
			checkAnswer(Answer, Final, Number); // compare with use's answer and right answer and show if it's right or wrong
		}
	}
}

void doOneProblem(int& Ans) {
	cin >> Ans;
}

void CalculateCorrectAnswer(int X, int Y, char F, int& A) { // generate correct answer with givin value X,Y with given function F than return A
	if (F == '+') {
		A = X + Y;
	}
	if (F == '-') {
		A = X - Y;
	}
	if (F == '*') {
		A = X * Y;
	}
}

void checkAnswer(int Ans, int A, int &Num) { //compare right answer than user's answer than answer if it's right or wrong

	if (Ans == A) {
		cout << "Correct" << endl;
		Num++;
	}
	else {
		cout << "Incorrect" << endl;
	}
}

void generateOperands(char& F) { // just little trick for generate fixed function
	cout << " " << F << " ";
}
Hi,
Firstly, your code looks pretty good.

> So far I got the all the things work without last part which is :

Set#1: You got 2 correct out of 3 for 66.7%
Set#2: You got 2 correct out of 3 for 66.7%
Set#3: You got 1 correct out of 3 for 33.3%
Overall you got 5 correct out of 9 for 55.6%


Is this the only problem you are trying to solve? :)
yes i tried to solve the last section not really working
ok i figured out
Topic archived. No new replies allowed.