Thread: Just need help getting started

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    20

    Just need help getting started

    So for my problem they give us scores for a section. And there are a number of sections that they could give us in the class. I have to tell how many A's, B's, C's, D's and F's are received in the class and also the highest, lowest and average of the scores.

    I know I need to use a loop but since this is the first loop we have ever done I am really stuck at the beginning. I just need help getting started then I will be able to do the rest on my own. So far this is what I have but I do not know how to start the first loop, once I can do that then I can do the rest of the loops and finish the problem.

    Code:
    // Purpose: This program will process grades in different
    //          sections. Then using all the sections and grade
    //          averages produce a summary including the number
    //          of sections, number of scores and average of scores.
    //
    // Input  : No input will be prompted.
    //
    // Output : The output will show a label for the section, the counts
    //          for each grade, lowest score, highest score and average.
    //          
    //          int lowest score         float average
    //          int highest score        
    //
    //---------------------------------------------------------------------
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    int main()
    {
       int section;   // section number
       int high;       // highest score of section
       int low;        // lowest score of section
       int scores;
       float averagesection;  // average of all scores in the section
       int totalsections;  // total number of sections
       int totalscores;    // total number of scores
       int classaverage;   // average scores of class
       int TOTAL_OF_A, TOTAL_OF_B, TOTAL_OF_C, TOTAL_OF_D, TOTAL_OF_F;
       int TotalofA;       // total number of A's
       int TotalofB;       // total number of B's
       int TotalofC;       // total number of C's
       int TotalofD;       // total number of D's
       int TotalofF;       // total number of F's
       
       cout << fixed << showpoint << setprecision(2);
               
       while (  )
         
            
            
       return 0;
       
    }
    I know you are not going to give me answers for my homework, I am just asking for help getting started.

  2. #2
    Registered User
    Join Date
    Sep 2010
    Posts
    20
    Here is an example since I am bad at explaining things. Again I do NOT want you to do it, I just need help starting it.

    Sample input 1
    2 80 97
    5 69 79 89 99 58
    7 60 70 80 90 100 0 59
    Sample output 1
    2 80 97

    Scores for section 1
    A's: 1
    B's: 1
    C's: 0
    D's: 0
    F's: 0
    Lowest Score: 80
    Highest Score: 97
    Average Score: 88.50

    5 69 79 89 99 58

    Scores for section 2
    A's: 1
    B's: 1
    C's: 1
    D's: 1
    F's: 1
    Lowest Score: 58
    Highest Score: 99
    Average Score: 78.80

    7 60 70 80 90 100 0 59

    Scores for section 3
    A's: 2
    B's: 1
    C's: 1
    D's: 1
    F's: 2
    Lowest Score: 0
    Highest Score: 100
    Average Score: 65.57


    Total number of sections: 3
    Total number of scores: 14
    Class Average: 73.57

    That's all the sections!! Normal Termination.

  3. #3
    Registered User
    Join Date
    Sep 2010
    Posts
    20
    This is how far I have gotten so far, I do not know if I am on the right track or not so if anyone knows any hints or ideas for me that would be awesome. Thanks for reading

    Code:
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    int main()
    {
       int section;   // section number
       int high;       // highest score of section
       int low;        // lowest score of section
       int score;
       float averagesection;  // average of all scores in the section
       int totalsections;  // total number of sections
       int totalscores;    // total number of scores
       int averagescore;   // average scores of class
       int A_count = 0;
       int B_count = 0;
       int C_count = 0; 
       int D_count = 0; 
       int F_count = 0;
    
       
       cout << fixed << showpoint << setprecision(2);
       cout << "Scores for section." << endl;
       cin >>score;
               
       while ( score > 0 )
         {
             if ((score >= 90) && (score <= 100)) A_count++;
             else if ((score >= 80) && (score < 90)) B_count++;
             else if ((score >= 70) && (score < 80)) C_count++;
             else if ((score >= 60) && (score < 70)) D_count++;
             else F_count++;
        
         }
         
         cout << "A's: " << A_count << endl;
         cout << "B's: " << B_count << endl;
         cout << "C's: " << C_count << endl;
         cout << "D's: " << D_count << endl; 
         cout << "F's: " << F_count << endl;
            
       return 0;
       
    }

  4. #4
    Registered User
    Join Date
    Oct 2010
    Posts
    45

    Help

    If sections is determined when the program is run, that should be your main loop. Then entered scores should be inside of that.

    I wouldn't enter the number of scores per section, but let the loop count them until you have an exit.

  5. #5
    Registered User
    Join Date
    Sep 2010
    Posts
    20
    So start my loop with
    while (section > 0 )

    We have to then have a cout that says how many sections there are total but I was trying to first get the program to read one score then I can add a loop to get it to read all the scores in the section and then add another loop to get it to read all the sections and put them together.

  6. #6
    Registered User
    Join Date
    Sep 2010
    Posts
    20
    • ctrl-d will trigger an end of file on standard input

    can someone tell me what this means please? Does it mean instead of hitting enter, you hit ctrl-d to make the cout statements appear?

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Ctrl-D is the Linux/UNIX EOF indicator. It appears, based on the spec in your assignment, that you're not to prompt for input, instead perhaps reading from a file?

  8. #8
    Registered User
    Join Date
    Oct 2010
    Posts
    45

    His problem

    I would think that since it is his first loop, I somehow doubt they have covered reading from files. I see what you are saying from his first section though. "// Input : No input will be prompted."

    Go with your first idea then to input the number of scores in the section to use for your first loop.

    Code:
    Total Sections<-
    
    Loop{Total Sections}
    {
         Loop{Scores in Section}
         {
              Enter Score<-
                 AddToGrade++   (as you have works)
                 AddToTotal++
         }
    DisplayGrades                 (again as you have already)
    
       (Total/Scores)
    DisplayAvgScore
    }
    Something like that is what your thinking, I think.
    Last edited by Incantrix; 10-10-2010 at 06:40 PM.

  9. #9
    Registered User
    Join Date
    Sep 2010
    Posts
    33
    Here’s something to get you started if you’re still stuck.

    But you need to find out where your data is and how you are going to access it.

    Note: I have a propensity for using for loops, but you can use something else.

    Code:
    #include <iostream>
    #include <sstream> // stringstream
    using namespace std;
    
    int main()
    {
        int cnt_A;
        int cnt_B;
        int cnt_C;
        int cnt_D;
        int cnt_F;
    
        int val;
        int val2;
    
        // Where's your data?
        // I've put it in a stringstream
        stringstream ss (stringstream::in | stringstream::out);
        ss << "2 80 97 5 69 79 89 99 58 7 60 70 80 90 100 0 59";
    
        for (int i = 1; i < 4; i++) // performs 3 loops, 1 per section
        {
            cout << "Scores for section " << i << endl;
    
            cnt_A = 0;
            cnt_B = 0;
            cnt_C = 0;
            cnt_D = 0;
            cnt_F = 0;
    
            ss >> val; // outputs next integer value from string ss because val declared as integer
    
            for (int j = 0; j < val; j++) // loops for val number of times, 2, then 5, then 7
            {
                ss >> val2; // outputs next value in string ss as integer
    
                if (val2 > 89)
                    cnt_A = cnt_A + 1;
                else if (val2 > 79)
                    cnt_B = cnt_B + 1;
                else if (val2 > 69)
                    cnt_C = cnt_C + 1;
                else if (val2 > 59)
                    cnt_D = cnt_D + 1;
                else if (val2 < 60)
                    cnt_F = cnt_F + 1;
    
            } // end j loop
    
            cout << "grade A's " << cnt_A << endl;
            cout << "grade B's " << cnt_B << endl;
            cout << "grade C's " << cnt_C << endl;
            cout << "grade D's " << cnt_D << endl;
            cout << "grade F's " << cnt_F << endl;
    
        } // end i loop
    
        return 0;
    }

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    In case you're stuck, I would suggest you write down the application flow on a paper. That is, write down what should happens, and after that if this happens, jump there, etc. Look out flowcharts.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Sep 2010
    Posts
    20
    Code:
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    int main()
    {
    int score; // input variable
    
    int section = 0;
    int high_score = 0; // highest score of section
    int low_score = 0; // lowest score of section
    float average_section = 0; // average of all scores in the section
    float average_score = 0; // average scores of class
    int total_sections = 0; // total number of sections
    int total_scores = 0; // total number of scores
    int A_count = 0;
    int B_count = 0;
    int C_count = 0;
    int D_count = 0;
    int F_count = 0;
    int loop_count = 0;
    
    cout << fixed << showpoint << setprecision(2);
    cin >>section;
    cin >>score;
    
    loop_count = section;
    while (loop_count == section)
    {
    
    if ((score >= 90) && (score <= 100)) A_count++;
    score++;
    if ((score >= 80) && (score < 90)) B_count++;
    score++;
    if ((score >= 70) && (score < 80)) C_count++;
    score++;
    if ((score >= 60) && (score < 70)) D_count++;
    score++;
    if (score < 60) F_count++;
    score++;
    total_scores = score + 1;
    loop_count = loop_count + 1;
    
    cout << "A's: " << A_count << endl;
    cout << "B's: " << B_count << endl;
    cout << "C's: " << C_count << endl;
    cout << "D's: " << D_count << endl;
    cout << "F's: " << F_count << endl;
    
    cout << "Total number of scores: " << total_scores << endl;
    cout << "Total number of sections: " << section << endl;
    
    
    cout << endl << "That's all the sections!! Normal Termination." << endl;
    
    }
    
    return 0;
    
    }
    This is what I have.
    Here are the "hints" the teacher gave us:
    • Work on getting your program to process one score.
    • Once your program can process one score, add a loop to process all of the scores in one section.
    • Once you program can process a section of data, add an outer loop to process multiple sections.
    • Remember that several variables will need to be reset at the beginning of each section, but other variables , those for class statistics, should not be reset.
    • ctrl-d will trigger an end of file on standard input.
    • The Class Average is computed as the sum of all students’ scores divided by the number of students and is NOT the average of the section averages. Be careful declaring your variables as the correct type.


    My program reads the first number and gives the correct number of sections and gives the correct letter grade for the first program. But i do not know how to make it read the next number.

  12. #12
    Registered User
    Join Date
    Sep 2010
    Posts
    20
    I tried using michael's idea but it said <sstream> not found

  13. #13
    Registered User
    Join Date
    Sep 2010
    Posts
    33
    Well, the data you presented is a bit confusing because it suggested input from a file, 2 scores: 80, 97; 5 scores: 69, 79, 89, 99, 58; etc

    And also you have stated above: ‘No input will be prompted.’

    Anyway, I’m not suggesting this is good coding practise, but you can try adding these few lines to get you moving and then you will find you have a load of bugs to sort out.

    Code:
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    int main()
    {
    int score; // input variable
    
    int section = 0;
    int high_score = 0; // highest score of section
    int low_score = 0; // lowest score of section
    float average_section = 0; // average of all scores in the section
    float average_score = 0; // average scores of class
    int total_sections = 0; // total number of sections
    int total_scores = 0; // total number of scores
    int A_count = 0;
    int B_count = 0;
    int C_count = 0;
    int D_count = 0;
    int F_count = 0;
    int loop_count = 0;
    
    cout << fixed << showpoint << setprecision(2);
    
    cout << "Enter section number: ";           /////////////////////////////////
    cin >>section;
    ///////////cin >>score;
    
    loop_count = section;
    while (loop_count == section)
    {
        cout << "\nEnter scores for section " << section << ", ctrl-d to exit" << endl;       //////////////////////////////////
        while (cin >> score)                 ///////////////////////////////////
        {
            if ((score >= 90) && (score <= 100)) A_count++;
            score++;
            if ((score >= 80) && (score < 90)) B_count++;
            score++;
            if ((score >= 70) && (score < 80)) C_count++;
            score++;
            if ((score >= 60) && (score < 70)) D_count++;
            score++;
            if (score < 60) F_count++;
            score++;
            total_scores = score + 1;
        }
    
        cin.clear(); ////////////////////////////////////////////
        loop_count = loop_count + 1;
    
        cout << "A's: " << A_count << endl;
        cout << "B's: " << B_count << endl;
        cout << "C's: " << C_count << endl;
        cout << "D's: " << D_count << endl;
        cout << "F's: " << F_count << endl;
    
        cout << "Total number of scores: " << total_scores << endl;
        cout << "Total number of sections: " << section << endl;
    
    
        cout << endl << "That's all the sections!! Normal Termination." << endl;
    
    }
    
    
        
    
    
        return 0;
    }
    Last edited by Michael432000; 10-12-2010 at 03:46 PM.

  14. #14
    Registered User
    Join Date
    Sep 2010
    Posts
    33
    Syntax for your if statements is wrong.

    Code:
    if ((score >= 90) && (score <= 100)) A_count++;
            score++;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help getting started...
    By Sh4d0ws in forum C Programming
    Replies: 0
    Last Post: 12-05-2009, 04:14 PM
  2. Get Started with lame
    By evstevemd in forum C++ Programming
    Replies: 15
    Last Post: 08-28-2009, 07:16 AM
  3. Help getting started :(
    By blackocellaris in forum C Programming
    Replies: 4
    Last Post: 11-05-2006, 06:50 PM
  4. How to get started?
    By anoopks in forum Linux Programming
    Replies: 0
    Last Post: 01-14-2003, 03:48 AM
  5. Need help getting started
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 09-02-2001, 11:08 PM