Question

#include<iostream> #include<cstdlib> using namespace std; int main() {     // create array of size 20    ...

#include<iostream>

#include<cstdlib>

using namespace std;

int main()

{

    // create array of size 20

    int arr[20];

   

    int i;

   

    cout<<"scores : ";

    for( i = 0 ; i < 20 ; i++ )

    {

        // generate a random number i range 70 - 100 an add it to arr

        arr[i] = rand() % 31 + 70;

       

        cout<<arr[i]<<" ";

    }

   

    // store the total score

    int total = 0;

   

    // store the highest score

    int highest = 0;

   

  // calculate the total score and the highest score

    for( i = 0 ; i < 20 ; i++ )

    {

        total += arr[i];

       

        // if the current score is more than the highest score

        if( arr[i] > highest )

            highest = arr[i];

    }

       

    // calculate average

    double average = (double)total / 20.0;

   

    cout<<"\n   ave : "<<average<<endl;

    cout<<" high : "<<highest;

   

    return 0;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1


#include<iostream>
#include<cstdlib>

using namespace std;

int main() {
    // create array of size 20
    int arr[20];

    int i;

    cout << "scores : ";
    for (i = 0; i < 20; i++) {
        // generate a random number i range 70 - 100 an add it to arr
        arr[i] = rand() % 31 + 70;

        cout << arr[i] << " ";
    }

    // store the total score
    int total = 0;

    // store the highest score
    int highest = 0;

    // calculate the total score and the highest score
    for (i = 0; i < 20; i++) {
        total += arr[i];

        // if the current score is more than the highest score
        if (arr[i] > highest)
            highest = arr[i];
    }

    // calculate average
    double average = (double) total / 20.0;

    cout << "\n   ave : " << average << endl;
    cout << " high  : " << highest;

    return 0;
}
Add a comment
Know the answer?
Add Answer to:
#include<iostream> #include<cstdlib> using namespace std; int main() {     // create array of size 20    ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT