Please help c++ program

This is a discussion on Please help c++ program within the C++ Programming forums, part of the General Programming Boards category; I need help with the char function where i have to take the % and change it to the corresponding ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    15

    Exclamation Please help c++ program

    I need help with the char function where i have to take the % and change it to the corresponding grade . and also the output function which has to look like this , we use setw()

    Code:
    ----------------------------
        |  EXAM  |  SCORE  | GRADE |
        ----------------------------
        |  HIGH  |   100   |   A   |
        ----------------------------
        |   AVG  |    83   |   B   |
        ----------------------------
        |   LOW  |    61   |   D   |
        ----------------------------
        |    1   |   100   |   A   |
        ----------------------------
        |    2   |    73   |   C   |
        ----------------------------
        |    3   |    94   |   A   |
        ----------------------------
        |    4   |    61   |   D   |
        ----------------------------
        |    5   |    87   |   B   |
        ----------------------------
    
    
    
    # include <iostream.h>
    # include <iomanip.h>
    # include <math.h>
    
    // This program asks the user to enter a series of test scores //
    // Then it will determine the highest , lowest , and average scores//
    // The corresponding letter grade will be assigned to the scores//
    // And finally a table of output will be displayed//
    
    
    
    
    
    // ***** VARIABLE DECLARATIONS ******//
    
    
    int promptscore (void);
    
    void displayoutput (int[], int );
    
    char examgrade (int);
    
    int avggrade ( int[], int );
    
    int highestgrade ( int [], int );
    
    int lowestgrade (int [] , int );
    
    void clearscreen (void);
    
    const int maxels = 8; //maximum # of array elements
    
    int examscore [maxels];
    
    
    
    
    
    //****** MAIN PROGRAM BODY *************//
    
    main ()
    
    {
    
         int score , i = 0;
    
         clearscreen();
    
         score = promptscore();
    
    
         while (score = 0 && i < maxels )
         {
              examscore[i++] = score;
    
              if ( i < maxels )
    
                   score = promptscore();
    
         }
    
    
    
         displayoutput(examscore , i);
    
    }
    
    //****** THIS IS THE PROMPT FOR SCORE FUNCTION******//
    
    
         int promptscore(void)
         {
    
              int examscore;
    
              cout << " enter score , enter a negative number to quit : ";
              cin >> examscore;
    
              return examscore;
    
    // ******* THIS IS THE FUNCTION FOR HIGHEST GRADE *******//
    
    
    
         int highestgrade ( int exam [], int nbrofexams)
         {
    
              int i , highestgrade;
    
              highestgrade= exam[0];
    
              for ( i = 0; i < nbrofexams; i++)
    
              {
    
                   if (exam[i] > highestgrade)
    
                   highestgrade = exam[i];
    
              }
    
         }
    
    
    // ********** THIS IS THE LOWEST SCORE FUNCTION ********//
    
    
          int lowestgrade ( int exam [], int nbrofexams)
    
          {
    
               int i , lowestgrade;
    
               lowestgrade= exam[0];
    
               for ( i = 0; i < nbrofexams; i ++ )
    
               {
    
                    if( exam [i] < lowestgrade)
    
                    lowestgrade = exam[i];
    
               }
    
    
          }
    
    //*** THIS IS THE INCOMPLETE !!!!!!! AVERAGE GRADE FUNCTION *****//
    
    
    
         float averagegrade ( int grade [] , int n )
    
         {
    
              int sum = 0;
    
              for ( int i = 0 ; i < n; i ++ )
    
                   sum += grade [i];
    
              return  (sum) / n;
    
    
         }
    
    
    
    
    
    //!!!!!!!!!!!!! CHAR EXAM GRADE FUNCTION !!!!!!!!!!!!!!//
    
    
    
    
    // !!!!!!!!!!!!!! CLEAR SCREEN FUNCTION !!!!!!!!!!!!!!!!!!//
    
    
    void clearscreen(void)
    {
         cout << "\033[2j\033[h";
    
    }
















    // !!!!!!!!!!!!! DISPLAY OUTPUT FUNCTION !!!!!!!!!!!!!!!!!!!!!!//

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,652
    What exactly do you need help with?

    No one here is going to your homework for you.

    gg

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,453
    What's so diificult about
    if ( score >= 90 ) grade = 'A';
    and so on through the score ranges

    > while (score = 0 && i < maxels )
    You don't want an assignment there. From code elsewhere, I guess you meant
    while (score > 0 && i < maxels )

    > int i , highestgrade;
    Having a local var with the same name as the function is very poor style. Name shadowing (where an inner scope name hides an outer scope name) can lead to all sorts of fun.
    Besides, there is no
    return result;
    in these functions

    > void displayoutput (int[], int );
    Naming parameters is a good idea - especially when you start writing code which spans many files.

    You also seem to have creeping indentation. The file is becoming progressively more indented as you go.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    15
    you have to understand this is my first programming class , i was just asking for some help i have no idea how to go about forming the table for the output I know i can make a const char line = "-------------" to make the first line and divider lines too i guess but putting it all together is where im a little flustered

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    15
    i dont think the functions were supposed to return results , simply do the work so that it can be outputted into the final table

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,453
    So write some code which has a few cout statements to ouput the raw information.

    cout << "HIGH" << highestgrade << endl;

    One you've outputted all the information, then start refining the formatting by using setw() and some cout statements for the dashes.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Mar 2004
    Posts
    15
    was just looking for some help finishing my last 2 functions , im not a kid im trying to learn this stuff at 28 years old and never having a c or c++ class before

    so cut me some slack im not asking anyone to do my homework for me i got most of it done myself

  8. #8
    Registered User
    Join Date
    Mar 2004
    Posts
    15
    im just having trouble putting everything together , i have most of it but just not sure how to complete it ,, i dont know its frustrating im sure youre looking at this like youre kidding right but its supposed to be an intro class and believe it or not theres 6 of us left in the class from over 20

  9. #9
    Registered User
    Join Date
    Mar 2004
    Posts
    44
    it is not that tough if you think about it you put your graes in a heap and the heap is already sorted then you take all the grades in the heap and add them together then divide by how many tests there are and if you want you can use modulus to find the exact average you dont need hardly any of that stuff that you are doing now but you might have to read about heaps if you dont know

  10. #10
    Registered User
    Join Date
    Mar 2004
    Posts
    15
    this is the way we were supposed to do it for class , he named the functions and said do the program

  11. #11
    Registered User
    Join Date
    Mar 2004
    Posts
    44
    you can still use heaps just read up on them you will understand

  12. #12
    Registered User
    Join Date
    Mar 2004
    Posts
    15
    ok ill look it up

  13. #13
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    Originally posted by ysuguy
    this is the way we were supposed to do it for class , he named the functions and said do the program
    >was just looking for some help finishing my last 2 functions , im not a kid im trying to learn this stuff at 28 years old and never having a c or c++ class before

    Don't worry about it Everyone has to start somewhere, and were here to help.

    My FULL advice on this one, is pseudo code! Write out everything you need to do in your program, and examine how you would do it with what you know and whats required. Then start writing your functions. If you have good pseudo code everything will make sense to you.

    >was just looking for some help finishing my last 2 functions

    But, beyond that..what functions do you need help with? And what do you need them to do?
    Last edited by Tronic; 03-27-2004 at 03:30 PM.
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  14. #14
    Registered User
    Join Date
    Mar 2004
    Posts
    15
    well i guess if i sit down ill be able to figure out my output table , and for my char function i need it to assign a grade to the test %


    so i guess all i do is take the inputted grade and do the

    if ( grade > 90 )
    grade = 'A'

    i know thats rough but the idea

    im worried about setting the table

  15. #15
    Registered User
    Join Date
    Mar 2004
    Posts
    15
    By the way salem I went to your website , and im not here trying to get people to do my homework i had 80-85% of it done myself . You have to remember this is my first class , and also that you were not born a computer genius . Im just trying to get through school while working full time to better my career .

    Not looking for a free ride this was my first ever post for help

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21