Need to use one parameter to give values to multiple variables

Write your question here.

I need to use a single parameter in doOneSet to give values to three differnt variables in int mainn to send to printReport so the user can see how many he or she got correct. So how do you get a single parameter to give a value to a different variable every time the function is called?












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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# include <iostream>
# include <cstdlib>
# include <ctime>
using namespace std;
void doOneSet(char, int&, int);
void getProbsPerSet(int&);
void printReport(int&, int&, int&);




int main()
{
	
	static int
		correct_add,
		correct_subtract,
		correct_multiply;
		
	int
		number_correct=0,
		probsPerSet;

	srand(static_cast<unsigned>(time(0)));

	getProbsPerSet(probsPerSet);
	
	doOneSet('+', probsPerSet, number_correct);
	doOneSet('-', probsPerSet, number_correct);
	doOneSet('*', probsPerSet, number_correct);
	printReport(correct_add, correct_subtract, correct_multiply);

}







void getProbsPerSet(int &probsPerSet)
{

	cout << "Enter how many problems will be generated per set: ";
	cin >> probsPerSet;
	cout << endl;



}







void doOneSet(char opprand, int& probsPerSet, int correct)
{

	int first_random_number,
		second_random_number,
		actual_answer,
		answer_entered_by_the_user,
		count=0;
	




	switch (opprand)
	{

	case '+':
		for (int i = 0; i < probsPerSet; i++)
		{

			first_random_number = rand() % (101);
			second_random_number = rand() % (101);
			actual_answer = first_random_number + second_random_number;
			cout << first_random_number << " + " << second_random_number << " = ";
			cin >> answer_entered_by_the_user;

			if (answer_entered_by_the_user == actual_answer)
			{
				cout << "CORRECT!" << endl;
				count++;
			}
			else {
				cout << "sorry, but that is incorrect..." << endl;
			}
		}
		break;

	case '-':
		for (int i = 0; i < probsPerSet; i++)
		{

			first_random_number = rand() % (101);
			second_random_number = rand() % (101);
			actual_answer = first_random_number - second_random_number;
			cout << first_random_number << " - " << second_random_number << " = ";
			cin >> answer_entered_by_the_user;

			if (answer_entered_by_the_user == actual_answer)
			{
				cout << "CORRECT!" << endl;
				count++;
			}
			else if (answer_entered_by_the_user != actual_answer) {
				cout << "sorry, but that is incorrect..." << endl;
			}
		}
		break;

	case '*':
		for (int i = 0; i < probsPerSet; i++)
		{

			first_random_number = rand() % (101);
			second_random_number = rand() % (101);
			actual_answer = first_random_number * second_random_number;
			cout << first_random_number << " * " << second_random_number << " = ";
			cin >> answer_entered_by_the_user;

			if (answer_entered_by_the_user == actual_answer)
			{
				cout << "CORRECT!" << endl;
				count++;
			}
			else {
				cout << "sorry, but that is incorrect..." << endl;
			}

		}	
	}
	


}







void printReport(int& correct_add, int& correct_subtract, int& correct_multiply){
	
	cout << endl;
	cout << correct_add << endl;
	cout << correct_subtract << endl;
	cout << correct_multiply << endl;
	cout << endl;
}
I think you might be confused. Your function is taking in 3 arguments. A char called opprand, a reference to a location of an int called probsPerSet, and an int called correct. Not sure why you want to use a reference though.

void doOneSet(char opprand, int& probsPerSet, int correct)

But every time you call this function in main with different values it will return a different value every time. If that makes sense.
Topic archived. No new replies allowed.