Thread: 1st Assignment

  1. #1
    Registered User
    Join Date
    Sep 2006
    Location
    Brooklyn, NY
    Posts
    21

    1st Assignment

    I have this program which I have to do. I am stuck because I haven't been programming in a while, therefore I forgot a couple of things. If anyone would be able to help me with anything and get me started with this program, I would be very grateful.

    Here it is:
    This Program should calculate weighted averages of grades. The program should also help answer this question: “how much to I have to get on the final in order to get an (x)?”

    The program should open with heading on the screen which asks the user how many tests will be given during a semester. Then, the program should this number, n, and an empty integer array, percentages, to a void function. The void function should fill percentages by asking the user what percent of the grade is each test. The sum of all the percentages must be 100. If it is not there should be error message which should make the user reenter the information.

    Once the percentages array is full, you should give the user one of two options. (Each of these options should be done by done by a separate function)

    1) Allow the user to enter the n test grades and calculate the weighted averages of the grades.

    2)Allow the user to enter in n-1 grades. First ask the user which test grade, k, the user is not entering (note 1<=k<=n.) Then enter in all but the k-th grade (hint: use continue in a for loop). Ask the user what he would like to get above as an average. Call this double variable above. Then calculate and print what the student needs to get in the k-th test to earn a grade higher then above. Now simply solve for x.)

    Once this is done, allow the user to enter in the information for another student, or an option to stop.

    Any help is greatly appreciated.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Post any of your attempts.

    Since the percentages are integers, you could use an array with 100 elements to store the grades; that would be the most grades you could have (if 0% is invalid).
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Location
    Brooklyn, NY
    Posts
    21
    Well, I'm just blanking on this.

    Ok. First will come the printf statement which the user will give the N number of grades. N will be the number given to an integer array (percentages [n]. How do I write this so far? What will be the code?

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    printf() the question (like "How many grades are there?") and scanf() the answer. You can declare the array to be 100 in size, but only use the number of elements that the user entered.

    [edit] You've covered functions, right? [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Good post Zeff, but I have no idea what you're stuck on!

    You have forgotten some things - but I have no idea what it is that you've forgotten, so I have no clue how to help you. Ironically, you may have forgotten what it is that you've forgotten, and have no clue either on how to proceed! (okay, enough humor for now)

    Post up what you've got as pseudocode to solve this and I'll be back in 1 hour to assist. I'm sure others will, as well - but we'd like to see your work, and much more specific questions on what's got you stumped.

    Here's some info on using weighted averages:

    Grades are often computed using a weighted average. Suppose that homework counts 10%, quizzes 20%, and tests 70%.

    If Pat has a homework grade of 92, a quiz grade of 68, and a test grade of 81, then
    Pat's overall grade = (0.10)(92) + (0.20)(68) + (0.70)(81) = 79.5

    Remember to use two equal signs for an equality test, not just one like silly Mathematicians!

    Back in 1 hour, show me what you've got, regards,

    Adak

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    :mrgreen:
    Only PHPBB boards have the mrgreen smiley.

    Since the number of grades entered varies, to calculate the average you'd use something like this:
    Code:
    int x, sum = 0;
    double average;
    
    for(x = 0; x < grades; x ++) {
        sum += grade[x];
    }
    
    average = sum / grades;
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Registered User
    Join Date
    Sep 2006
    Location
    Brooklyn, NY
    Posts
    21
    Ok. so,

    Int n=0;
    int percentages[]; // it should be empty

    Printf("How many grades: ");
    scanf("%d",&n);

    How do I then send the number N and the empty interger to a viod function?

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Code:
    int percentages[]; // it should be empty
    No it shouldn't. That won't compile. As I said, put 100 in there because that's the most you'll need.
    How do I then send the number N and the empty interger to a viod function?
    Pass parameters. http://www.cprogramming.com/tutorial/c/lesson4.html
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Registered User
    Join Date
    Sep 2006
    Location
    Brooklyn, NY
    Posts
    21
    Thanks !

    I'll do the lesson.

    2 years ago when I was programming, i knew all this stuff. I just forgot simply everything.

  10. #10
    Registered User
    Join Date
    Sep 2006
    Location
    Brooklyn, NY
    Posts
    21
    Ok, so something like this?

    Int n=0;
    int percentages[100];
    void fill (int n, int []);

    Printf("How many grades: ");
    scanf("%d",&n);

    and then

    fill(n, percentages);

    ??

  11. #11
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Yes, the actual declaration of the function would look like this (sort of like main()):
    Code:
    void fill(int n, int array[]) {
    
    }
    where array is whatever you want to call the grades array.

    BTW, printf() is spelled with a lowercase 'p'. C is case-sensitive. Int is int, etc.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  12. #12
    Registered User
    Join Date
    Sep 2006
    Location
    Brooklyn, NY
    Posts
    21
    Ohh ok.

    void fill(int n, int percentages[]);

  13. #13
    Registered User
    Join Date
    Sep 2006
    Location
    Brooklyn, NY
    Posts
    21
    so passing to the function is correct

    ex

    fill(n,percentages) ?

  14. #14
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Code:
    void fill(int n, int percentages[]);
    Exactly. That's the prototype. For the declaration, leave out the ; and add a block {} (like main()).

    so passing to the function is correct

    ex

    fill(n,percentages) ?
    Yes.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  15. #15
    Registered User
    Join Date
    Sep 2006
    Location
    Brooklyn, NY
    Posts
    21
    Ok thanks.

    So now i try to write the whle function:

    This is what it should do: The void function should fill percentages by asking the user what percent of the grade is each test. The sum of all the percentages must be 100. If it is not there should be error message which should make the user reenter the information.

    So,

    void fill(int n, int percentages[])
    {
    int ??? what do I need to declare here?

    printf("What is the first test grade: ")
    scanf(" .... how do I fill the array with the appropriate test grade and then ask what percentage it is?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 02:34 AM
  2. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 09:46 PM
  5. Replies: 1
    Last Post: 10-27-2006, 01:21 PM