### 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.

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:

 1234567891011 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 " <

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:
 12345 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,
this could be a
first attempt

Warning
@Uk Marine
this is Out of bounds
 123456789101112131415161718 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!
 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 //Scores.cpp //## #include 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 "<>array[i]; }//end for }//end function enter_scores void display_scores(int array[],int const SIZE){ cout<<"\nScores"<
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.