1. ## Lowest Score Drop

Well, first of all, I would just like to say that I have half of the program right (at least I think that i have it right).

My program is supposed to do three things:
1. void getscore()-should ask the user for a test score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the five scores to be entered.
2. voidcalcAverage()-should calculate and display the average of the four highest scores. This function should be called just once by main, and should be passed the five scores
3. int findLowest()-shoudl find and return the lowest of the five scores pased to it. It should also be called by calcAverage, who uses the function to determine which of the five scores to drop

Code:
```#include <iostream>
#include <conio>
using namespace std;

//Function prototype
void getscore(int&, int&, int&, int&, int&);
void findLowest (int, int, int, int, int, int);
void calcAverage (double)
int main()
{
int LO, score1, score2, score3, score4, score5;

getscore (score1, score2, score3, score4, score5);
findLowest(LO, score1, score2, score3, score4, score5);

getch();
return 0;
}

void getscore (int &score1, int &score2, int &score3, int &score4, int &score5)
{
cout << "Enter first score: ";
cin  >> score1;
cout << "Enter second score: ";
cin  >> score2;
cout << "Enter third score: ";
cin  >> score3;
cout << "Enter fourth score: ";
cin  >> score4;
cout << "Enter fifth score: ";
cin  >> score5;
}

int findLowest(int LO, int score1, int score2, int score3, int score4, int score5)
{

if((score1<score2)&&(score1<score3)&&(score1<score4)&&(score1<score5))
{
LO=score1;
cout << LO;
}

else if((score2<score1)&&(score2<score3)&&(score2<score4)&&(score2<score5))
{
LO=score2;
cout <<LO;
}

else if((score3<score1)&&(score3<score2)&&(score3<score4)&&(score3<score5))
{
LO=score3;
cout << LO;
}

else if((score4<score1)&&(score4<score2)&&(score4<score3)&&(score4<score5))
{
LO=score4;
cout << LO;
}
else if((score5<score1)&&(score5<score2)&&(score5<score3)&&(score5<score4))
{
LO=score5;
cout << LO;
}
}```
But, now I am having trouble with the void calcAverage() part. this function should calculate and display the average of the four highest scores. This function should be called once by main, and should be passed the five scores.
Does anyone have any idea how to do that  2. Have you learnt how to use loops and arrays? Doing it this way is rather tedious. 3. No, not really. Someone suggested that i used a loop, but I don't really see how that is possible. I am trying to stick to what I know. 4. Suppose I changed the requirements and told you that you now have to deal with 1000 scores. I think you will find that your current method becomes rather impossible, unless you write a program to generate the resulting program for you. But to write that second program, you probably have to use loops.

You might want to take some time to learn about loops and arrays. When used appropriately, they can simplify things and make life easier for you. 5. how can I use a loop in a function?? Is that even possible? What type would I use? Do/while, for, while??? 6. how can I use a loop in a function?? Is that even possible?
Of course it is possible. The tutorial I linked to has a code snippet with a for loop in the main() function.

What type would I use? Do/while, for, while?
Probably a for loop since you will be looping over an array with known bounds. 7. Code:
```#include <iostream>

using namespace std;

int main()
{
char c;
int i;

// a do loop will go into the loop _at least_ once
do
{
cout << "enter a character or 'q' to stop: ";
cin >> c;
} while (c != 'q');

// a while loop checks the condition before entering the loop, ie it is not guaranteed to enter even once
while (c != 'q')
{
cout << "this wont get executed since: c == 'q'";
}

// for loop will loop until the middle statement (i < 3) is false, in this case 3 times
for (i = 0; i < 3; i++)
{
cout << "iteration #" << i << endl;
}
}``` 8. ??? I'm confused 9. I think nadroj was just demonstrating the possible loops without particular reference to your question. 10. oh okay sorry
Thanks again 11. yes, as laserlight stated, i was just giving very basic examples of the three loops, without your homework.. so you can learn it.

copy the code and run it.. and try and change things around. 12. Code:
`Snipped ;)`
Note you still need to modify this. Notably in the calcAverage() function - you wanted the top 4 however in this case it gets the average of all the inputted scores. Also, if you want a constraint of having 5 scores then you will need to change the code to enforce it. These should be pretty simple modifications - if you still can't do them - start reading up on loops and vectors. 13. Code:
`snipped with 0rion's code, for now` 14. Of course you can use STL functions to simplify them - but then he won't learn how loops are used  15. My point is that naya22 has not yet come back with code using what was recommended and demonstrated earlier in this thread: let's be patient and wait before giving out more code, especially that which is so close to the answer. Popular pages Recent additions 