negative number help!
My code runs, but for some reason my average is coming back with a negative number...
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 51
|
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
double score[5] = {0.0,0.0,0.0,0.0,0.0};
double lowest = 0.0;
double highest = 0.0;
double avg = 0.0;
double sum = 0.0;
for (int i = 0.0; i<5; i = i + 1)
{
score[i] = 0.0;
}
cout << "You will be asked to enter 5 scores."<< endl;
for (int i = 0.0; i<5; i = i + 1)
{
cout << "Please enter a score: ";
cin >> score[i];
}
lowest = score[0];
for (int i=1; i<5; i=i+1)
{
if (score[i] < lowest)
{
lowest = score [i];
}
}
highest = score[0];
for (int i=1; i<5; i=i+1)
{
if (score[i] > highest)
{
highest = score[i];
}
}
for (int i=1; i<5; i=i+1)
{
avg = sum + score[i] - lowest - highest;
}
cout << "Lowest Score: " <<lowest<<endl;
cout << "Highest Score: " <<highest<<endl;
cout << "Average score with highest score and lowest score excluded: " <<avg<<endl;
system("pause");
return 0;
}
|
Topic archived. No new replies allowed.