Enter five scores and display the lowest score and the difference of each score from the highest score.

I'm so confused. I don't know if i'll use array or looping. Need you help. Thanks

You need a loop to collect the scores, a variable to store the highest value found, and an array to store them in. Then another loop to find the difference between each value and the highest value that you stored in the variable in the first loop.

You have to write the code. We don't do your homework for you.

Enter five scores and display the lowest score
and the difference of each score from the highest score.

You will need two loops and an array to hold the 5 scores.

In the first loop, you can take in the 5 scores into the array and also find the lowest and highest score.

Hint ... set the 1st score that you take in to be both the lowest and highest score ...

Then for the next 4 scores, compare each next score to lowest and highest and update lowest and highest as needed.

So now you can print out the lowest and highest scores ...

On second loop though the array of scores... you can find and print out the difference of each value from the 'highest value' that you found above.

Edited 1 Year Ago by David W

#include<iostream>
using namespace std;

int main()
{
int myArray[5];
int i;
int lowest;


for ( i=0; i<5; i++)
{

cout<< "Scores[" << i << "]:";
cin >> myArray[i];
}

lowest=myArray[0];


for (i =0; i<5; i++)
{
if(myArray[i]<lowest)
{
lowest=myArray[i];
}
}

cout << "\nThe Lowest numbers is " << lowest << endl;

system("pause>0");
return 0;
}

This is my program but how can i subtract the highest score to the other scores?

Edited 1 Year Ago by mike_2000_17: duplicate... sorry.. deleted the wrong duplicate

You could try something like this (that also validates input) ...

int main()
{
    int ary[5] = {0}; // get 'array' to hold 5 ints ...
    int low, high;

    // take in loop ...
    for( int i = 0 ; i < 5 ;  )
    {
        cout << "Enter integer # " << (i+1)  << " (of 5) "<< ": ";
        if( cin >> ary[i] )
        {
            if( i == 0 ) low = high = ary[0];
            else
            {

                if( ary[i] < low ) low = ary[i];
                else if( ary[i] > high ) high = ary[i];
            }
            ++i ;
        }
        else
        {
            cin.clear(); // clear error flags
            cin.sync(); // 'flush' cin stream ...
            cout << "\nERROR! Only integers are valid input here ...\n\n";
        }
    }

    cout << "\nLow is  :  " << low << endl;
    cout << "\nHigh is :  " << high << endl;


    // ...


}

Edited 1 Year Ago by David W

This article has been dead for over six months. Start a new discussion instead.