Need help with a Test average application

I need help with an assignment that makes me create a program to calculate test averages, it would be helpful to give me answers by the 14th, because thats when my trimester ends. Plz help
Hi. If you need help, feel free to inbox me. I will gladly help you out but I won't be giving any direct answers.
Show us what you've written so far, and explain what problems you're having.

It would be helpful if you could do this by the 14th, because that's when your trimester ends.

#include <iostream>
#include <string>
#include <cstring>
#include <stdlib.h>

using namespace std;

int main(int argc, char* argv[])
{
int scores[5], temp;
do {
cout << "Please enter a score: ";
cin >> scores[0];
} while(scores[0] < 0 || scores[0] > 100);

for(int i = 1; i < 5; i++){
do {
cout << "\n\nPlease enter a score: ";
cin >> scores[i];
} while(scores[i] < 0 || scores[i] > 100);

if(scores[i] < scores[0]) {
temp = scores[i];
scores[i] = scores[0];
scores[0] = temp;
}
}

double average = (scores[1] + scores[2] + scores[3] + scores[4]) / 4;
cout << "\n\nAverage of the four highest scores: " << double(average) << "\n\n";

return 0;
}


When I execute it, It gives me "Please enter a score:" about one hundred times, and when i do enter a score it does nothing.
Would I have to put something into stdin inputs?
This program works as expected for me when I enter scores between 1-100. It successfully takes the average of the top 4 scores and outputs it.

do {
cout << "\n\nPlease enter a score: ";
cin >> scores[i];
} while(scores[i] < 0 || scores[i] > 100);


Get rid of the do while loop as it serves no purpose.

Can you please explain more what the program is supposed to do, like what scores should be accepted and what problems you are having.
Last edited on
ok, i got it working, it was the program i was using(i was using jdoodle at first), i put the code on onto visual studio and it worked, Thank you for helping me and taking your time to answer.
Topic archived. No new replies allowed.