Geting intergers from function to function.

Im not sure how to get the integers from my score function into my average function thanks.

Also like to say im a long time viewer of this awesome website. Im currently in pf2 sadly i have not done c++ for over 2 years college is expensive so im extremely rusty thanks.

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
#include <iostream>
 #include <iomanip>
using namespace std;


void getScores(int&, int&, int&, int&, int&);
void showAverage(int&, int&, int&, int&, int&);

int main(){

	int grade1, grade2, grade3, grade4, grade5;
	

	getScores(grade1, grade2, grade3, grade4, grade5);
	showAverage(grade1, grade2, grade3, grade4, grade5);

	

	

	system("pause");
	return 0;
}


int getScores(int &input1, int &input2, int &input3, int  &input4, int &input5){
	cout<<"Enter 5 grades "<<endl;
	cin>>input1>>input2>>input3>>input4>>input5;
}

int showAverage(int &num1, int &num2, int &num3, int  &num4, int &num5){
	int sum;
	cout<<"Now it will calculate average "<<endl;
	sum = ((num1 + num2 + num3 + num4 + num5) / 5);
	cout<<"Sum is "<<sum<<endl;

	if (sum>=90)
		cout<<"Your grade value is A \n";
	else if (sum>=80)
		cout<<"Your grade value is B \n";
	else if (sum>=70)
		cout<<"Your grade value is c \n";
	else if (sum<=69)
		cout<<"Your grade value is F \n";


}
Last edited on
There is all o'k with passing integers from one function to another. The problem is that your functions are defined as returning an object of type int while they return nothing. You could correct the code by simply substitution of the return type int for type void.
Last edited on
OMG thanks lol ive been trying to figure it out for hours just changing 2 words fix its lol thanks alot
Topic archived. No new replies allowed.