after a lot of fussing, my code finally compiles properly.
but once again, its not calculating the things i want.
PROBLEM:
doesnt calculate "scores entered by user"
doesnt calculate "highest max score"
doesnt calculate "lowest min score"
as far as the scores entered by user...
i was hoping this..
if user entered 99, 88, 77, 66, etc, it would show up just as is...
like... Scores entered: 99 88 77 66
it worked before with my old program, and im trying to match it with an older program of mine, and it would give me errors. so i just stuck with it and decided to ask for help.
anyway, i apologize for the lengthy INT MAIN. my teacher doesnt want subprograms in this one, soo the int main is lengthy as heck!
anyway, if someone can take a look and spy whats wrong, thank u
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
|
#include <fstream>
#include <iostream>
using namespace std;
// STRUCTure
struct Score
{
int value;
Score* next; // the link
};
// main hub for all
int main()
{
//create an empty linked list
Score* head = 0;
// prompt for how many students
int nScores;
cout << "How many scores would you like to view? ";
cin >> nScores;
cin.ignore(1000, 10);
cout << " " << endl;
// read and save the scores
for (int count = 0; count < nScores; count++)
{
// read score from user
Score* aScore = new Score;
cout << "Enter score: ";
cin >> aScore->value;
cin.ignore(1000, 10);
// add node (stack model)
aScore->next = head;
head = aScore;
}
// traverse list
int sum = 0;
int count = 0;
Score* p;
for (p = head; p; p = p->next)
{
sum += p->value;
count++;
}
// print results
if (count > 0)
{
float average = float(sum) / nScores;
cout << "The average of " << nScores << " scores is " << average << endl;
}
// print the scores entered
cout << "Scores entered: ";
cout << count << ' ';
cout << endl;
// print the max and min scores
int aScore;
int max = aScore;
int min = aScore;
for (count = 0; count < aScore; count++)
{
if (max < aScore) max = aScore;
if (min > aScore) min = aScore;
}
cout << " " << endl;
cout << "highest score: " << max << endl;
cout << "lowest score: " << min << endl;
// count# of scores that are A,B,C,passing grades
int nAgrade = 0;
for (p = head; p; p = p->next)
{
if (p->value >= 90) nAgrade++;
}
cout << "Number of A scores: " << nAgrade << endl;
int nBgrade = 0;
for (p = head; p; p = p->next)
{
if (p->value >= 80 && p->value < 90) nBgrade++;
}
cout << "Number of B scores: " << nBgrade << endl;
int nCgrade = 0;
for (p = head; p; p = p->next)
{
if (p->value >= 70 && p->value < 80) nCgrade++;
}
cout << "Number of C scores: " << nCgrade << endl;
int nPassing = 0;
for (p = head; p; p = p->next)
{
if (p->value >= 70 && p->value <= 100) nPassing++;
}
cout << "Number of passing scores: " << nPassing << endl;
cin.ignore();
cin.get();
return 0;
}
|