Thread: Don't even know where to start.... do while...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    16

    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.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is if/else statements.

    Kuphryn

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    60

    Post

    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.

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    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?

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    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...

  6. #6
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    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);
    }
    *Cela*

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    36

    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....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Adventures in labyrinth generation.
    By guesst in forum Game Programming
    Replies: 8
    Last Post: 10-12-2008, 01:30 PM
  3. C++ gui for windows where to start
    By prixone in forum Windows Programming
    Replies: 2
    Last Post: 12-16-2006, 11:48 PM
  4. GNOME Desktop won't start (Mandriva)
    By psychopath in forum Tech Board
    Replies: 10
    Last Post: 07-19-2006, 01:21 PM
  5. Start bar color in WinXP
    By confuted in forum Tech Board
    Replies: 4
    Last Post: 05-03-2003, 06:18 AM