# Don't even know where to start.... do while...

• 02-05-2003
thynksheraze
Don't even know where to start.... do while...
ok, this is what i have to do. Using a 90, 80, 70, 60 percent grading scale, if given a list of test scores, print the number of A's, B's, C's, and D's using a do while loop. Terminate the list of scores with a sentinel value.

I am not even sure where to start. so far we only know very basic things... no special header files except iostream, iomanip, cstring. Tis' all. Can anyone help me out? I'd appreciate it every much.
• 02-05-2003
kuphryn
One solution is if/else statements.

Kuphryn
• 02-05-2003
NickESP
I'm a complete novice, but one way I can think of is to declare an int for each grade grouping(50-70, 70-100 etc) and start you're do...while loop for the lowest grade category. This first do...while will increment(gradeD++) while the incoming grades fall into this category. After this do...while has completed, execution will move to another do...while that assesses the grades falling into the next highest category. Do the same for the next two categories. Of course there will be grades left on the list, simply place this whole procedure into a while loop that keeps a check on the list of grades and stops looping when all of the grades are removed/read from the list.
• 02-05-2003
alpha
if you are given the file, read the file into an array, and then loop through the array, and then increment the number of each certain grade. use if statements like kuphryn said...and print the number of each grade. not that difficult...

by the way, what do you mean very basic things, have you learned about arrays?
• 02-05-2003
DougDbug
Maybe something like this?
Code:

```int CountA = 0; //... int CountD = 0; do     // Get input value     // If > 59 and < 70 CountD++     // If > 69 and < 80 CountC++     // If > 79 and < 90 CountB++     // If > 90 CountA++ }while(Input != SentenialValue):    // Or, you can subtract cout << CountA << " As" << endl //etc...```
• 02-05-2003
Cela
Here's another way with tables :-)
Code:

```#include <iostream> using namespace std; char letter_grade(int score) {   int values[] = {90, 80, 70, 60};   int grades[] = {'A','B','C','D'};   int max_letters = sizeof(grades) / sizeof(grades[0]);   for (int i = 0; i < max_letters; i++)   {     if (score >= values[i])     {       return grades[i];     }   }   return 'I'; // Return incomplete } int main() {   int i = 0;   int scores[] = {97, 62, 84, 76, 92, 78};   int n_grades = sizeof(scores) / sizeof(scores[0]);   do   {     cout<< letter_grade(scores[i]) <<endl;   } while (++i < n_grades); }```
• 02-05-2003
beginner
User input
Okay here's an working example assuming that the user inputs the data from the keyboard... the only thing you would have to do is read from the file in the similar way..:)
Code:

```#include <iostream> //#include <cstring> using namespace std; int main() {         int n;         int As = 0;         int Bs = 0;         int Cs = 0;         int Ds = 0;         int Fs = 0;         do         {                 cout << "Enter a grade percentage:" << endl;                 cin >> n;                 if(n>=90)                 {                         cout << "The letter grade is A" << endl;                         As ++;                 }                 else if(n>=80)                         cout << "The letter grade is B" << endl; // Add Bs like I added As                 else if(n>=70)                         cout << "The letter grade is C" << endl; // Add Cs like I added As                 else if(n>=60)                         cout << "The letter grade is D" << endl; // Add Ds like I added As                 else if(n<60)                         cout << "The letter grade is F" << endl; // Add Fs like I added As         }         while(cin); // loops until u hit ctrl Z or any other character but digit         cout << "NO. of As: " << As << endl;         // cout All other grades like above...         return 0; }```
thought this gives you a little more idea....