Thank you so much for the tips.................
Brownie
This is a discussion on lowest test score within the C++ Programming forums, part of the General Programming Boards category; Thank you so much for the tips................. Brownie...
Thank you so much for the tips.................
Brownie
Last edited by brown34; 05-12-2002 at 07:21 AM.
ughh... can you put that in code braces please next time!!
ok, your problem is that the function scopes out and you loose all your data because you have not returned it back to main!! I see you are confused with the right way to use functions. you see, the ( braces ) send information to your function, and your return will send back the information.
1. Your predefs have a vairable name, this is not neccesary because all you need to see is the type of variable, like so
void calcAverage(int test1, int test2, int test3, int test4, int test5, int lowest);
-to-
void calcAverage(int , int , int , int , int , int );
2. Are you trying to use pointers or references here:
void getValues(int& test1, int& test2, int& test3, int& test4, int&
test5)
3. not void main, int main the the correct way
this is my edited code of yours, it works but there may be a few advanced things running around in there:
Code:#include <iostream.h> struct tests { int test1; int test2; int test3; int test4; int test5; }; //Function Prototype tests getValues(); int findlowest(tests); void calcAverage(tests, int); int main() { tests marks; marks = getValues(); calcAverage(marks, findlowest(marks)); return 0; } tests getValues() { tests marks; cout << "Enter first test score\n"; cin >> marks.test1; cout << "Enter second test score\n"; cin >> marks.test2; cout << "Enter third test score\n"; cin >> marks.test3; cout << "Enter fourth test score\n"; cin >> marks.test4; cout << "Enter fifth test score\n"; cin >> marks.test5; return marks; } int findlowest (tests lowest) { int low; if (lowest.test1 < lowest.test2) { low = lowest.test1; } else { low = lowest.test2; } if (low > lowest.test3) { low = lowest.test3; } if (low > lowest.test4) { low = lowest.test4; } if (low > lowest.test5) { low = lowest.test5; } return low; } void calcAverage(tests marks, int low) { float average; average=((marks.test1 + marks.test2 + marks.test3 + marks.test4 + marks.test5) - low)/5.0; cout << "The average test score is: " << average; }