I'm having troubles with calculating the new score and calculating and displaying the difference between each new score and the average of new scores.
we learned arrays yesterday and i feel completely lost.
I got some of the new score calculated but its coming out completely wrong and i dont even know how to start to calculate and display the difference between each new score and the average of new scores.
#include <iostream>
usingnamespace std;
int main()
{
//Write a program that uses an integer array to store 12 test scores that a user enters
int a[12];
int i=0;
cout << "Please enter the scores: ";
for(i=0;i<12;i++)
{
cin>>a[i];
}
//Calculates the highest score
int max=a[0];
for(i=0;i<12;i++)
{
if(a[i]>max)
max=a[i];
}
cout << "The highest score is: ";
cout << max << endl;
//Use following formula to calculate and display the new scores:
//original score/highest score * 100, only display the whole number part of the new score
int newScore;
newScore=(a[i])/(max)*100;
cout << newScore << endl;
int sum=0;
for(i=0;i<12;i++)
sum+=a[i];
cout << "The average is: " << sum/30;
//Calculate and display the difference between each new score and the average of new scores.
return 0;
}
#include <iostream>
usingnamespace std;
int main()
{
//Write a program that uses an integer array to store 12 test scores that a user enters
int AllScores[12];
int i = 0;
// Output message asking user to enter the scores
cout << "Please enter the scores. \n";
for (int i = 0; i < 12; ++i)
{
// User inputs a score.
cout << "Input: ";
cin >> AllScores[i];
cout << endl;
}
//Calculates the highest score
int max = 0;
for (int i = 0; i < 12; ++i)
{
// If the value stored in array is larger than
// current max, then change max to new max value.
if (AllScores[i] > max)
max = AllScores[i];
}
cout << "The highest score is: ";
cout << max << endl;
//Use following formula to calculate and display the new scores:
//original score/highest score * 100, only display the whole number part of the new score
float newScore = 0;
for (int i = 0; i < 12; ++i)
{
// Note that dividing the same score will result in 1 and * 100 means 1*100 = 100
newScore = ((AllScores[i]) / (max)) * 100;
cout << "New Score [" << (i + 1) << "]: " << newScore << endl;
}
int sum = 0;
for (int i = 0; i < 12; ++i)
sum += AllScores[i];
// Final Output
cout << "The average is: " << (sum / 12) << endl;
// Wait for user to press any of the character or return keys
system("pause");
//Calculate and display the difference between each new score and the average of new scores.
return 0;
}
One Thing I noticed is that you weren't specifying the type for "i" in your for loops.
Try this out, I didn't try to compile it though, but most likely works.
That would be the scores input into the array you created.
Since you're in a for() loop, and you defined int i = 0, the i would be whatever iteration of i is at that point and since you're only iterating by 1 each time it would be.
1 2 3 4 5 6 7 8 9 10 11 12
for(int i = 0; i < 12; ++i)
{
newScore = (a[i] / max) * 100;
// What i would look like in each loop run
// i = 0, i = 1, i = 2, i = 3, i = 4 ... i = 11
// Lets say that our first number is the max number "500"
// newScore = (a[0] / max) * 100
// newScore = (500 / 500) * 100;
// newScore = 1 * 100;
// newScore = 100;
}
Edit** I just read the name of who posted that question, lol... Sorry MilkeyBoy