When you return the value from findLowest() you aren't assigning that value to anything. You should have in main:
lowest = findLowest(lowest);
Setting the variable "lowest" to anything in the function findLowest() will not affect your global variable "lowest" because you did not pass it in by reference. You are only editing a local varible in the scope of the findLowest() function.
ctaylo21
Junior Poster in Training
67 posts since May 2010
Reputation Points: 10
Solved Threads: 11
There is no need to for any static variables, use local variables instead by removing the static keyword. Also, maybe you should use a do-while loop when checking the input in getScore? What happens if the user inputs an incorrect value twice? There is no point in checking the argument to getScore before the user has been able to input any value. I do not think you ment to call getScore inside the findLowest function?? By doing this you are asking the user for 10 values..
rxlim
Junior Poster in Training
51 posts since Feb 2011
Reputation Points: 12
Solved Threads: 8
One other thing to note is that the first value the user inputs will, at the time, also be the lowest value.
rxlim
Junior Poster in Training
51 posts since Feb 2011
Reputation Points: 12
Solved Threads: 8
first :
cout << "The lowest score is: " << lowest << endl;
lowest is not inialized so it will be automatically inialized 0 so whatever values you write will be zero so you should call function
cout << "The lowest score is: " << findLowest(lowest) << endl;
second :
the function findLowest has a mistake in that it compares the last two values only and sets the lowest you can correct this by making the compiler compare every two values in list by making a variable that will take the lowest and compare it with next value
please mark the thread as solved if you've got the help you need :)
reemhatim
Junior Poster in Training
50 posts since Sep 2010
Reputation Points: 5
Solved Threads: 2
The for loop is correctly used, but when you ask the user for input in getScore you do not know how many times the user will input an incorrect value. Therefore it could be a good idea to do something like this:
int input = 0;
do {
cout << "Input value: ";
cin >> input;
} while (input < 0 || input > 100);
if the user inputs an incorrect number. A normal while loop would also work.
rxlim
Junior Poster in Training
51 posts since Feb 2011
Reputation Points: 12
Solved Threads: 8