Member Avatar for lee.martin.568847

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 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;
    }

Recommended Answers

All 6 Replies

program does not work:

Can you alaborate a little more than that?

Your fist for loop needs to have its statements wrapped in brackets since there are multiple lines.

for(int i = 0; i < 7; i++)
{
    //code here
    //code here
}

You are never multiplying the total by the difficulty.

cout << "Scores = " << score << endl;

score is (effectively) a pointer. Your code will output a hexadecimal address. I expect you want to output each score.

for (int i=0; i<7; i++)
{
  cout << score[i] << " ";
}

Also, this:
for (unsigned int i=0, Total=0;

create a whole new unsigned int variable named Total, which is used inside the loop, and ceases to exist when the loop ends; the original Total variable is completely untouched. This is commonly known as shadowing and is generally considered a bad idea.

Also your input doesn't check for bad input or find max and min:

    double best = 0;
    double worst = 100;
    cout << "Enter the difficulty level (1.2 - 3.8):";
    cin >> difficulty;
    if (difficulty < 1.2)
        difficulty = 1.2;
    if (difficulty >3.8)
        difficulty = 3.8;
    for( unsigned int i = 0; i < 7; i++ )
    {
        std::cout << "Enter the score of judge " << i+1 << ": " << std::flush;
        std::cin >> score[i];
        if (score[i] > 10)
            score[i] = 10;
        if (score[i] < 0)
            score[i] = 0;
        if (score[i] > best)
            best = score[i];
        if (score[i] < worst)
            worst = score[i];
        Total += score[i];
    }
    Total = (Total - (best + worst)) * difficulty
Member Avatar for lee.martin.568847

Thanks, much better, however the difficulty is not used except for verification and output, the total should not include best and worst, which may not be 10 and 0????

#include<iostream>

using namespace std;
int main()


    {



    int score[7];
    double difficulty;//1.2 to 3.8 
    double Total ;
     double best = 10;
double worst = 0;

    // start loop


    cout << "Enter the difficulty level (1.2 - 3.8):";
    cin >> difficulty;
     if (difficulty < 1.2)
difficulty = 1.2;
if (difficulty >3.8)
difficulty = 3.8;
for( unsigned int i = 0; i < 7; i++ )


    {


     std::cout << "Enter the score of judge " << i+1 << ": " << std::flush;
     std::cin >> score[i];

 if (score[i] > 10)
score[i] = 10;
if (score[i] < 0)
score[i] = 0;
if (score[i] > best)
best = score[i];
if (score[i] < worst)
worst = score[i];
Total += score[i];

        for (unsigned int i=0, Total=0; i < 7; i++)
         Total += score [i] ;
    }
    // display output end loop

    cout << "Scores = "; 
        for (unsigned int i=0, Total=0; i < 7; i++)
    {
cout << score[i] << " " << std::flush;


Total = ((Total - (best + worst))*  0.6);
    {
cout <<endl;  
    cout<< "Total score = "<< Total  << endl;
    cout<< "Difficulty level = "<< difficulty <<endl;

    system("PAUSE");
}   return 0;}

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.

According to that it seems to indicate that the total score is adjusted by the difficulty rating.

    include<iostream>    
    using namespace std;
    int main()
    {
        int score[7];
        double difficulty;//1.2 to 3.8
        double Total ;
        double best = 10;   
        double worst = 0;   
        // start loop
        cout << "Enter the difficulty level (1.2 - 3.8):";
        cin >> difficulty;
        if (difficulty < 1.2)    
        difficulty = 1.2;
        if (difficulty >3.8)
        difficulty = 3.8;
        for( unsigned int i = 0; i < 7; i++ )    
        {
            std::cout << "Enter the score of judge " << i+1 << ": " << std::flush;
            std::cin >> score[i];       
            if (score[i] > 10)
            score[i] = 10;
            if (score[i] < 0)
            score[i] = 0;
            if (score[i] > best)
            best = score[i];
            if (score[i] < worst)
            worst = score[i];
            Total += score[i];
        }
        Total = ((Total - (best + worst)) * difficulty * 0.6);      
        // display output end loop
        cout << "Scores = ";
        for (unsigned int i=0, Total=0; i < 7; i++)
        {   
            cout << score[i] << " " << std::flush;
        }
        cout <<endl;
        cout<< "Total score = "<< Total << endl;
        cout<< "Difficulty level = "<< difficulty <<endl;     
        system("PAUSE");    
        return 0;
    }

I would strongly encourage you to use the Code option when inputting your code. It allows you to keep the indent formatting, which is much easier to read.

Member Avatar for lee.martin.568847

Thanks so much for all of your help. I will be back when my next C++ class starts in July. I truly appreciate your help.
Lee

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.