Hello, I am having a problem with a program I am tying to wright. It tells me that I have to:
Create a 1-D Array to hold a set of exam scores:
55 74 93 84 64 72 69 78 87 84 72 33 83 68 62 51 88 90
Write a program to do the following tasks:
1. Display scores in rows of four(4) scores.
2. Calculate average score and display.
3. Find Lowest score and display.
4. Find Highest score and display.
1. How would I go about doing this would I use the "string" function or is there an easer why you can think of?
2. I thought I did every thing right for the average but it comes out to "3" witch obviously is not right (it should be 66.94)
3. I found the lowest score just fine :)
4. But some how I can not get the highest number to be right.
any help, pointers or suggestions etc. would be great! Thanks!
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 52 53 54 55 56
|
// main.cpp
// Program 6
// Created by William Blake Harp on 7/10/14.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int exam_scores[] = {55, 74, 93, 84, 64, 72, 69, 78, 87, 84, 72, 33, 83, 68, 62, 51, 88, 90};
int const SIZE = sizeof(exam_scores)/sizeof(exam_scores[0]);
int sum_of_exam_scores;
double average;
int count;
int highest_exam_score;
int lowest_exam_store;
for (sum_of_exam_scores = 0; sum_of_exam_scores != SIZE; sum_of_exam_scores++)
{
sum_of_exam_scores += exam_scores[0];
average = sum_of_exam_scores / SIZE;
cout << "The average of the exam scores are: " << average << endl;
break;
}
highest_exam_score = exam_scores[0];
for (count = 1; count != SIZE; count++)
{
if (exam_scores[count] > highest_exam_score)
{
highest_exam_score = exam_scores[count];
cout << "The highest exam score is: " << highest_exam_score << endl;
break;
}
}
lowest_exam_store = exam_scores[0];
for (count = 1; count != SIZE; count++)
{
if (exam_scores[count] < lowest_exam_store)
{
lowest_exam_store = exam_scores[count];
cout << "The lowest exam score is: " << lowest_exam_store << endl;
break;
}
}
|