Very new, struggling with reference variables/parameters

So I have an assignment I'm trying to finish in which i need to calculate the average of a group of 5 scores, but the lowest one is dropped. I'm given the following functions : void getScore() which asks for 5 scores and stores in reference parameter variables and validates it.
the second function im given is: void calcAverage() which finds the average of the 4 scores, after it calls the function "int findLowest()", which finds the lowest score and drops said score from the group of numbers

Here is a really rough draft of what i have so far, I'm pretty sure i need to use reference variables for parameters:

#include <iostream>
using namespace std;

void getScore(&int);
void calcAverage();
int findLowest();

int main()
{
int test1, test2, test3, test4, test5;

getScore(test1);
getScore(test2);
getScore(test3);
getScore(test4);
getScore(test5);

calcAverage(test1, test2, test3, test4, test5);

return 0;
}

void getScore(int&test1)
{

cout << "Please enter test score: ";
cin >> test1;

return;
}

void calcAverage()
{
findLowest()
}

int findLowest(test1, test2, test3, test4, test5)
{
int lowest;
lowest = test1;
if (test2 < lowest)
lowest = test2;
if (test3 < lowest)
lowest = test3;
if (test4 < lowest)
lowest = test4;
else if (test5 < lowest)
lowest = test5;
}
Your question is??
Please read http://www.cplusplus.com/forum/beginner/1/
do you have knowledge of arrays? because using an array would make this assignment much easier to complete.
Don't think I'm supposed to use arrays, but I've been working on it, and here's a more updated version of what i have now. I believe it's simply a matter of reference variables, as i am still not completely confident in my use of them

#include <iostream>
using namespace std;

void getScore(int&testscore); //Prototypes
void calcAverage(int test1,int test2,int test3,int test4,int test5);
int findLowest(int t1, int t2, int t3, int t4, int t5);

int main()
{
int test1, test2, test3, test4, test5;

getScore(test1);
getScore(test2);
getScore(test3);
getScore(test4);
getScore(test5);

calcAverage(test1, test2, test3, test4, test5);

return 0;
}

void getScore(int&testscore) //Asks for test scores
{

cout << "Please enter test score: ";
cin >> testscore;

return;
}

void calcAverage(int test1,int test2,int test3,int test4,int test5)
{
int findLowest(int t1, int t2, int t3, int t4, int t5);
}

int findLowest(int test1,int test2,int test3,int test4,int test5)
{
int lowest;
lowest = test1;
if (test2 < lowest)// Determines lowest score
lowest = test2;
if (test3 < lowest)
lowest = test3;
if (test4 < lowest)
lowest = test4;
else if (test5 < lowest)
lowest = test5;
lowest = ((test1 + test2 + test3 + test4 + test5)-lowest) / 4; //Subtracts
//lowest score from total and finds average

cout << lowest;
return 0;
}
Are the functions that you have written the ones on the assignment sheet?

They look odd since findLowest is an integer, yet the average could well be a double.
There's a few things not going right here. Why does calcAverage just call getLowest?

And no matter what your lowest value is, the function is always returning 0. Wouldn't you want it to return the lowest value?
You should use arrays, as it will help make ur program simpler, plus you need to handle functions efficiently... and dont make average functions return type as int cuz then data will be lost...
You should use arrays, as it will help make ur program simpler, plus you need to handle functions efficiently... and dont make average functions return type as int cuz then data will be lost...
Your logic is correct, but your program doesn't work. You need to use cin.ignore after your cin extraction. Else you leave '\n' in the buffer. You aren't calling findLowest() correctly.
findLowest(test1, test2, test3, test4, test5); would be correct.

After that you just need a way to stop the program so you can see that final cout in find lowest.

Arrays would make this program better, but if you aren't allowed them then you can't use them.

I would say that the general principle of functions is portability. You don't want your findLowest to also find the average. Given five integers, findLowest() should return the lowest integer. Average should make the average calculation, and then return the average.

Finally back in main: cout << average.

The point is that once your findLowest() always and only finds the lowest, then any time you need to find the lowest you can just copy/paste it into your program.

Topic archived. No new replies allowed.