program that uses an integer array

Write a program that uses an integer array to store 12 test scores that a user enters. Then

1.Calculates the highest score

2.Use following formula to calculate and display the new scores: (original score)/(highest score)*100 (hint: make sure to get the decimal number). Only display the whole number part of the new score.

3.Calculate the average the new scores.

4.Calculate and display the difference between each new score and the average of new scores.

Can someone please help me out, with this question, I'm have hard time doing it..
Thank you.
Take it step by step,
Write a program that uses an integer array to store 12 test scores that a user enters


So an integer array with 12 elements ok that's easy int scores[12]; there, so now what...

Calculate the highest score


ok so i need a way to go through all these elements and figure out which element is the highest, hmm what is the first thing that comes in mind... well a loop could help me do that, i can loop through all these elements using a for loop (or any loop) and check which element is the largest using an if statement, syntax should look something like this:

1
2
3
4
5
6
7
8
9
10
11
int scores[12] = {1,5,3,4,6,7,8,2,4,10,2,4,2}; Edit://Added additional element, thanks for spotting my mistake.
int temp = 0;

for ( int i = 0 ; i < 13 ; ++i )
{
if (scores[i] > temp)
{
   temp = scores[i];
}
}
cout<<"The Largest score in is " <<temp<<endl;


i will leave the rest for you, like i said move through the questions step by step and you'll solve them eventually, if you've been paying attention during class that is :)


EDIT: If you want the user to enter the 12 elements of the array you can do it also with a loop, like this:
1
2
3
4
5
for ( int i = 0 ; i < 13; ++i )
{
   cout<<"Enter the value of the element at position #"i": ";
   cin>>scores[i];
}
Last edited on
Thank you very much, very helpful..
you're welcome, let me know if you need help with the other questions, show me what you've done so far
Hi @Ram1,
in addition to
@Uk Marine's advices
this could be a
first attempt

Warning
@Uk Marine
this is Out of bounds
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int scores[12] = {1,5,3,4,6,7,8,2,4,10,2,4};
for ( int i = 0 ; i < 13; ++i )


   value    position
    1         0
    5         1
    3         2
    4         3
    6         4
    7         5
    8         6
    2         7
    4         8
   10        9
    2        10
    4        11
    ??   12  <--??


If i am missing something
let me know pls!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//Scores.cpp
//##

#include <iostream>


using namespace std;

void keep_window_open();

void enter_scores(int array[],int const SIZE);
void display_scores(int array[],int const SIZE);



int main(){

        int const SIZE=12;
        int scores[SIZE];

        enter_scores(scores,SIZE);
        display_scores(scores,SIZE);
        keep_window_open(); //for ms windows 

return 0; //indicates success
}//end of main

void enter_scores(int array[],int const SIZE){
        cout<<"\nEnter "<<SIZE<<" scores"<<endl;
        for(int i=0;i<SIZE;i++){
                cout<<"Score "<<i+1<<": ";
                cin>>array[i];
        }//end for
}//end function enter_scores

void display_scores(int array[],int const SIZE){
        
        cout<<"\nScores"<<endl;
        for(int i=0;i<SIZE;i++){
                cout<<"Score #"<<i+1<<": "<<array[i]<<endl;
        }//end for
        cout<<endl;
}//end function display_scores

void keep_window_open(){
        cin.ignore(120,'\n');
        cout<<"Press Enter to exit. . . .";
        cin.ignore();
}//end function keep_window_open
Enter 12 scores
Score 1: 1
Score 2: 2
Score 3: 3
Score 4: 4
Score 5: 5
Score 6: 6
Score 7: 7
Score 8: 8
Score 9: 9
Score 10: 10
Score 11: 11
Score 12: 12

Scores
Score #1: 1
Score #2: 2
Score #3: 3
Score #4: 4
Score #5: 5
Score #6: 6
Score #7: 7
Score #8: 8
Score #9: 9
Score #10: 10
Score #11: 11
Score #12: 12

Press Enter to exit. . . .
Last edited on
Sorry, my mistake there it's my fault i didn't compile it
@Uk Marine do not worry
it happens!
Topic archived. No new replies allowed.