Using Array in for loop need assistance please

Getting error messages, program does not work:
Assignment:
In the sport of diving, seven judges award a score between 0 and 10, where each score may be a floating-point value. The highest and lowest scores are thrown out and the remaining scores are added together. The sum is then multiplied by the degree of difficulty for that dive. The degree of difficulty ranges from 1.2 to 3.8 points. The total is then multiplied by 0.6 to determine the diver’s score.
Write a computer program that inputs a degree of difficulty and seven judges’ scores, and outputs the overall score for that dive. The program should ensure that all inputs are within the allowable data ranges. To make your programming easier, if a number is out of range (greater than the upper limit or less than the lower limit), then let the program replace it with upper or lower limit numbers.
Hint: Use double Array and for loop statement to store each Judge’s score
Hint: Use highest variable with the initial value of 0, and lowest variable with the initial value of 10, in order to find out the highest and the lowest scores .
*** sample output
Please enter the difficulty level(1.2 - 3.8): 1
Enter the score of judge 1: 5
Enter the score of judge 2: 4
Enter the score of judge 3: 3
Enter the score of judge 4: 2
Enter the score of judge 5: 1
Enter the score of judge 6: 6
Enter the score of judge 7: 7
Scores = { 5 4 3 2 1 6 7 }
Difficulty level = 1.2
Total score = 14.4

My program:

#include<iostream>

using namespace std;
int score[7];

int main()

{
int difficulty;//1.2 to 3.8
int total;

// start loop

{

for (i=0, total=0; i < 7; i++)
total += score [i] ;

}
cout << "Enter the difficulty level (1.2 - 3.8):";
cin >> difficulty;

cout << "Enter the score of judge 1:";
cin >> score[0];
cout << "Enter the score of judge 2:";
cin >> score[1];
cout << "Enter the score of judge 3:";
cin >> score[2];
cout << "Enter the score of judge 4:";
cin >> score[3];
cout << "Enter the score of judge 5:";
cin >> score[4];
cout << "Enter the score of judge 6:";
cin >> score[5];
cout << "Enter the score of judge 7:";
cin >> score[6];

{
int total;
total=(score[0]+ score[1]+score[2]+ score[3]+score[4]+score[5]+score[6]);
return (total);
}

// display output end loop
cout << "Scores = " << score [];

<< endl;

system("PAUSE");
return EXIT_SUCCESS;}

Any help is appreciated. Thanks!
Last edited on
I've removed syntax errors:

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354`` ``````#include using namespace std; int score[7]; int main() { int difficulty;//1.2 to 3.8 int total; // start loop { for (int i=0, total=0; i < 7; i++)//*********************** total += score [i] ; } cout << "Enter the difficulty level (1.2 - 3.8):"; cin >> difficulty; cout << "Enter the score of judge 1:"; cin >> score[0]; cout << "Enter the score of judge 2:"; cin >> score[1]; cout << "Enter the score of judge 3:"; cin >> score[2]; cout << "Enter the score of judge 4:"; cin >> score[3]; cout << "Enter the score of judge 5:"; cin >> score[4]; cout << "Enter the score of judge 6:"; cin >> score[5]; cout << "Enter the score of judge 7:"; cin >> score[6]; { int total; total=(score[0]+ score[1]+score[2]+ score[3]+score[4]+score[5]+score[6]); return (total); } // display output end loop cout << "Scores = " << score //***************************** << endl; system("PAUSE"); return EXIT_SUCCESS;}``````

Total isn't used I think
I think he wanted help not for someone to do it for them. and using system pause isn't recommended. Same with global variables try putting the score array inside of the main function. not sure why you are returning exit success either most people on their main function just do return ( 0 ); ps
you can use a loop for getting the inputs something like
 ``12345`` ``````for( unsigned int i = 0; i < 7; i++ ) { std::cout << "Enter the score of judge " << i+1 << ": " << std::flush; std::cin >> score[i]; }``````

You can also use a loop for the total. it is NEVER good to have messy code like that where you list off each thing manually if you can use a loop like something easy like that then you should

After writing this I realized that you are using a loop to get the total score with a loop but you are doing that before getting the inputs and then getting the scores again after. why not just put the loop at the end and get rid of the other one? AND you also declare total twice.
PS try to use code tags eg
 `[code][/code]`
Last edited on
After reading responses, I made changes and I think I am getting closer, but the output is not right. Scores should be a list of the array values and Total score should be total *0.6. Also it should throw out highest and lowest and check that scores are within range of 0 to 10?????

using namespace std;
int main()

{
int score[7];
int difficulty;//1.2 to 3.8
int Total;

// start loop

cout << "Enter the difficulty level (1.2 - 3.8):";
cin >> difficulty;

for( unsigned int i = 0; i < 7; i++ )
{
std::cout << "Enter the score of judge " << i+1 << ": " << std::flush;
std::cin >> score[i];
}

{
for (unsigned int i=0, Total=0; i < 7; i++)
Total += score [i] ;
}

// display output end loop
cout << "Scores = " << score //*****************************

<< endl;
cout<< "Total score = "<< Total
<< endl;
system("PAUSE");
return 0;
}
Last edited on
using your last code
 ``1234567891011121314151617181920212223242526272829303132333435`` ``````using namespace std; int main() { int score[7]; int difficulty;//1.2 to 3.8 THIS SHOULD BE DECLARED AS DOUBLE, NOT INTEGER int Total; //INITIALIZE THIS TO 0 i.e. double Total(0.0); // start loop cout << "Enter the difficulty level (1.2 - 3.8):"; cin >> difficulty; for( unsigned int i = 0; i < 7; i++ ) { std::cout << "Enter the score of judge " << i+1 << ": " << std::flush; std::cin >> score[i]; } { for (unsigned int i=0, Total=0; i < 7; i++) Total += score [i] ; } // display output end loop for (unsigned int i=0;i<7;++i) cout << "Scores = " << score[i]<
part of the program working but need some help with the calculation and verification part??? Also the output of the score is not right. I have not submitted in Moodle yet.

Please review and let me know what I need to do to get the output of total score calculation and the scores displayed correctly.

#include<iostream>

using namespace std;
int main()

{
int score[7];
double difficulty;//1.2 to 3.8
double Total ;

// start loop

cout << "Enter the difficulty level (1.2 - 3.8):";
cin >> difficulty;

for( unsigned int i = 0; i < 7; i++ )
{
std::cout << "Enter the score of judge " << i+1 << ": " << std::flush;
std::cin >> score[i];
}

{
for (unsigned int i=0, Total=0; i < 7; i++)
Total += score [i] ;
}

// display output end loop
cout << "Scores = " << score << endl;
cout<< "Total score = "<< Total*0.6 << endl;
system("PAUSE");
return 0;
}
I copied the code from Matri X tried to run it and got error messages:
In function `int main()':
`cout' undeclared (first use this function)
`flush' is not a member of `std' `cout' is not a member of `std' `cin' undeclared (first use this function)

Last edited on
probably your compiler you can a either do what I was doing putting std:: infront of all the items in that namespace and remove the using namespace std or b remove the std:: namespace from the items and keep the using namespace std but option a would be recommended.
ps fix your line for scores and use a loop like for
 ``123456789`` ``````std::cout << "Scores = " << std::flush; //std is the namespace and I don't // ever include the whole namespace because I am not using everything in // it like vectors, strings, cin, getline, ifstream, ect... ( unsigned int i = 0; i < 7; i++ ) //unsigned means it will never be negative { std::cout << score[i] << " " << std::flush;//outputting all the scores then a space //flush means it doesn't move to next line but flushes the buffer } std::cout << std::endl;``````

ps it is bad practice to copy and past if you need help just ask

Oh and one more thing if your total score is multiplied by .6 then after you get the total score from the for loop you should prob put something like `Total *= .6 //same as Total = Total * .6 ` and to check to check and see if the scores are within a range just compare each one
Last edited on
Topic archived. No new replies allowed.