### Help with function returning wrong value

I'm currently taking a programming logic and design class and we're using C++ for our homework. I'm still a very fresh beginner - having trouble with assignment #9.

This is part of a larger assignment (using functions: enter six scores [0-100 range], drop the lowest score, calculate the average of the remaining five) - right now my "findLowest" function is returning "2" instead of whatever the real lowest score entered is.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576`` ``````#include #include #include #include using namespace std; //list of current functions void getScore(); //function for user to enter six scores int findLowest(int); //function for finding lowest of six scores int main () { //declare int lowest; getScore(); findLowest(lowest); cout << "\n" << endl; //making space in test runs, not important cout << "Lowest score is: " << lowest << endl; //hoping to display the lowest score system("PAUSE"); return 0; } //getScore function void getScore() { int testScore = 0; int counter = 0; //writes to a file ofstream scoreInput; scoreInput.open("scores.txt"); cout <<"Please enter the six test scores: " <> testScore; counter = ++counter; scoreInput << testScore <>testScore) { cout <

Currently I'm working on entering the scores and finding the lowest score, once that is done there is still more to build. I'm just currently stuck on getting this part to work before I move on.
Any help on that subject would be awesome.

Thanks!
Last edited on
Also - not as important - how do you make the code in the box that scrolls instead of just all posted long format?

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667`` ``````#include #include #include #include using namespace std; //list of current functions void getScore(); //function for user to enter six scores int findLowest(int); //function for finding lowest of six scores int main () { int lowest = 0; getScore(); lowest = findLowest(lowest); cout << "\n" << endl; //making space in test runs, not important cout << "Lowest score is: " << lowest << endl; //hoping to display the lowest score cin.get(); return 0; } //getScore function void getScore() { int testScore = 0; int counter = 0; //writes to a file ofstream scoreInput; scoreInput.open("scores.txt"); cout <<"Please enter the six test scores: " <> testScore; counter = ++counter; scoreInput << testScore <> lowest; //trying to find the lowest score entered on file while(scoreInput>>testScore) { if (lowest > testScore) { lowest = testScore; } } return lowest; }``````

You had several problems. You didn't assign a variable to your function findLowest() to collect the return value from the function. Also, Make sure you do you if statement checking inside the while loop so you can check each value from the file.
Last edited on
Thank you! I've made the changes you suggested and it worked!
But for this part : "lowest = findLowest(lowest);" - I'm embarrassed I missed that!

The other points you made, I will keep that in mind going forward.

Thank you again!
Topic archived. No new replies allowed.