Hey everyone,
I have a program named Star Search that I must do for my Computer Science class. I'm stuck because I can't seem to get the do while loop to function properly. Basically when the answer is y I want the program to loop, when it's n I want it to system pause, when it's not n or y I want it to output a prompt then request another input. The program seems to be starting on line 76.
Well, the good news is this code seems fine (I compiled it). Your error type seems a little more unusual. Have you switched over to another IDE? What IDE are you currently using? If it's Visual Studio, are the files you're accessing directly inside the projects folder?
I compiled it online just now and it is working fine which is weird. I'll try to copy and paste the code to my MacBook and see if it has the same issue. The average is still coming out wrong though.
Edit: I've figured out everything else but the answer loop is confusing me.
You're off to a great start. You're getting tripped up because line 24 is legal syntax, but does something very different from what you intend: double findHighest(highest), findLowest(lowest);
This actually defines two VARIABLES (not functions) called findHighest and findLowest. The variables are initialized from highest and lowest respectively. You should replace calcScore() with this code:
double findHighest()
{
// find and return the highest of the 5 scores
}
double findLowest()
{
// find and return the lowest of the 5 scores
}
void
calcScore()
{
double lowest = findLowest();
double highest = findHighest();
double total = s1 + s2 + s3 + s4 + s5;
// double average = (total - findHighest - findLowest) / 3;
double average = (total - highest - lowest) / 3;
cout << "Average score: " << average;
}
This defines the findLowest() and findHighest() functions. You will need to write the code to find them.
Have you learned about arrays? Using an array of scores for this assignment would make it a lot easier.
Also, note that findHighest() and findLowest() are returning doubles instead of int as the assignment asks. I believe that this is an oversight in the assignment but you should confirm with the professor.
Once you get this working, don't forget to modify main() to keep asking for scores for more performers as the assignment requires.