loops
Feb 21, 2016 at 11:41pm UTC
how would i display the amount of letter grades there are for example if there are three As in the finally section it should display A's: 3. im not very sure how to do that what my code has is a skeleton any help appreciated 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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
#include <iostream>
using namespace std;
int main()
{
const int MIN_VALUE = 1;
const int MAX_VALUE = 10;
const int SENTINEL = 999;
char letterGrade = ' ' ;
string teacherName = " " ;
string studentName = " " ;
string className = " " ;
int numStudents = 0;
int numTest = 0;
int counter = 0;
double testScore = 0;
double studentAverage = 0;
double classAverage = 0;
double totalGrade;
cout << "Enter the teachers name: " ;
cin >> teacherName;
getline (cin, teacherName);
cout << "Enter the class designation: " ;
cin >> className;
cout << "Enter the number of students: " ;
cin >> numStudents;
while (numStudents < 0)
{
cout << "Please enter a positive number: " ;
cin >> numStudents;
}
for (int x = 1; x <= numStudents; x++)
{
cout << "Enter students name: " ;
cin >> studentName;
getline (cin, studentName);
for (double loopCounter = 1, total = 0; loopCounter < MAX_VALUE; loopCounter++)
{
cout << "Please enter a number from 0 - 100 or type 999 to stop: " ;
cin >> testScore;
if (testScore != SENTINEL)
{
total += testScore;
studentAverage = total / loopCounter;
numTest++;
}
else
{
break ;
}
totalGrade = totalGrade + total;
}
cout << "Student Average: " << studentAverage << endl;
}
if (studentAverage > 90)
letterGrade = 'A' ;
else if (studentAverage >= 80)
letterGrade = 'B' ;
else if (studentAverage >= 70)
letterGrade = 'C' ;
else if (studentAverage >= 60 )
letterGrade = 'D' ;
else if (studentAverage <= 50)
letterGrade = 'F' ;
classAverage = totalGrade / numStudents;
cout << "Class average: " << classAverage << endl;
cout << "Teacher: " << teacherName << endl;
cout << "Class: " << className << endl;
while (counter > 1)
{
cout << "Student: " << studentName ;
cout << "\t\t Average: " << studentAverage ;
cout << " \t\tGrade: " << letterGrade << endl;
counter++;
}
cout << "Student count: " << numStudents << endl;
cout <<"Student average: " << classAverage << endl;
cout << "A's: " << endl;
cout << "B's: " << endl;
cout << "C's: " << endl;
cout << "D's: " << endl;
cout << "F's: " << endl;
}
Feb 21, 2016 at 11:44pm UTC
also for this area im supposed to show the out put of more than one student along with his/her grade and average and its only showing me the output of one student, i know the loop is wrong but im not quite sure which loop to use ive used a while loop, do while loop and for loop, although i believe i may be formatting the for loop incorrectly
1 2 3 4 5 6 7 8
while (counter > 1)
{
cout << "Student: " << studentName ;
cout << "\t\t Average: " << studentAverage ;
cout << " \t\tGrade: " << letterGrade << endl;
counter++;
}
Topic archived. No new replies allowed.