Now this one is due along with my other topic "Numbers in a file". Me and a classmate have been working on this one together for going on 3 straight hours and we can not figure out what we are doing wrong.
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 57 58 59 60 61 62 63 64
|
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
string name;
double score[20];
string student[20];
int number = 0;
double grade;
int count = 0;
double total = 0;
string best, worst;
while (grade != -1)
{
cout <<"Enter name and grade (or DONE -1 to quit): ";
student[count] = name;
score[count] = grade;
cin >> name >> grade;
if (grade > -1){
count++;
total += grade;
}
}
cout << "There were " << count << " grades." << endl;
cout << "The total was " << total << endl;
double ave = total / count;
cout << "The average was " << ave << endl;
cout << "The higest grade was ";
int big = 0;
for (int i = 0; i <= count; i++)
{
if (big >= grade)
{
grade = big;
cout << big;
}
}
cout << " and was made by ";
cout << name <<endl;
//cout << "The lowest grade was " << big << " and was made by " << student[4] << endl;
cout << "The following students made above average:";
for (int i = 0; i <= count; i++)
{
if(score[i] > ave)
{
cout << " " << student[i] << " " << score[i];
}
}
}
|
This code is supposed to output:
Enter name and grade (or DONE -1 to quit): Bob 91.5
Enter name and grade (or DONE -1 to quit): Bill 88
Enter name and grade (or DONE -1 to quit): Tim 75
Enter name and grade (or DONE -1 to quit): Kevin 99
Enter name and grade (or DONE -1 to quit): Sue 50
Enter name and grade (or DONE -1 to quit): Greg 10
Enter name and grade (or DONE -1 to quit): Mark 93
Enter name and grade (or DONE -1 to quit): DONE -1
There were 7 grades
The total was 506.5
The average was 72.3571
The highest grade was 99 and was made by Kevin
The lowest grade was 10 and was made by Greg
The following students made above average: Bob Bill Tim Kevin Mark Mike
The following students made below average: Sue Greg
break
We have been working on one section of code at a time but it just does not want to work for us. If anyone can provide any assistance in this matter, as these assignments are due tonight, it would be greatly appreciated and welcomed. (The break is not part of the output.)