Please help!!

/* I am trying to make a program that takes an average of two numbers using multiple functions and out put the results here is what I have so far*/
#include <iostream>
using namespace std;

void getMathScore(int);
void getChemScore(int);
void compAverage(int, int, int&);
void showResults(int, int, int);

void getMathScore(int a)
{
int mathScore = 0;
cout << "Enter your math score: ";
cin >> mathScore;
cout << mathScore;
}

void getChemScore(int b)
{
int chemScore = 0;
cout << "\nEnter your chem score: ";
cin >> chemScore;
cout << chemScore;
}
void compAverage(int a, int b, int& r)
{
int mathScore, chemScore, avg;
avg = (a + b) / 2;
cout << "\nYour average is: " << avg;
}

void avgNumRef (int mathScore, int chemScore, int avg)
{
cout << "\nYour math score is: " << mathScore;
cout << "\nYour chem score is: " << chemScore;
cout << "\nYour average score is: " << avg;
}

int main()
{
int mathScore, chemScore, avg;
getMathScore(mathScore);
getChemScore(chemScore);
compAverage(mathScore, chemScore, avg);
avgNumRef(mathScore, chemScore, avg);
return 0;
}
To thing to understand here is that, for example, the 'mathScore' variable in your main function is different than the 'mathScore' variable in your getMathScore function.

If you want the mathScore variable in main to be updated when you call getMathScore, you need to pass mathScore by reference instead of copying it.

e.g.
1
2
3
4
5
6
void getMathScore(int& mathScore)
{
    cout << "Enter your math score: ";
    cin >> mathScore;
    cout << mathScore;
}

Notice the type of the input parameter is int&, which means "reference to int".
Thank you very much I will make these changes.
SOLVED: I did not use multiple functions because I can not figure it out but this is what I have
#include <iostream>
using namespace std;

// Function prototype.
int addNum(int, int);
void addNumRef(int, int, int&);

int main()
{
int x = 0;
int y = 0;
int sum = 0;

cout << "Enter Math Score: ";
cin >> x;
cout << x;

cout << "\nEnter Chem Score: ";
cin >> y;
cout << y;
sum = addNum(x, y);
cout << "\nAverage: " << sum << endl;
cout << "Math Score: " << x << endl;
cout << "Chem Score: " << y << endl;
}

int addNum (int a, int b)
{
int temp;
temp = (a + b) / 2;
return temp;
}
Use code tags when you post code.
And "Please help!!" is an absolutely retarded title.
SOLVED 2: I figured it out thank you for all the help:
#include <iostream>
using namespace std;
int a;
int b;
int r;

void getMathScore(int& a)
{
cout << "Enter your math score: ";
cin >> a;
cout << a;
}

void getChemScore(int& b)
{
cout << "\nEnter your chem score: ";
cin >> b;
cout << b;
}
void compAverage(int& a, int& b, int& r)
{
r = (a + b) / 2;
cout << "\nYour average is: " << r;
}

void avgNumRef (int& a, int& b, int& r)
{
cout << "\nYour math score is: " << a;
cout << "\nYour chem score is: " << b;
cout << "\nYour average score is: " << r;
}

int main()
{
getMathScore(a);
getChemScore(b);
compAverage(a, b, r);
avgNumRef(a, b, r);
return 0;
}
@dutch where can i find how to use code tags
You just put this around your code. It keeps the indentation and adds syntax highlighting:

[code]
your code goes here
[/code]

How to use code tags:
http://www.cplusplus.com/articles/jEywvCM9/

HINT: you can edit your post and add code tags.

There are other tags available you can use:
http://www.cplusplus.com/articles/z13hAqkS/
Registered users can post here. Sign in or register to post.