Thread: Help! calculating grades

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    3

    Exclamation Help! calculating grades

    No matter which grade, the final letter grade is "F"

    please tell me where I've got it wrong

    Code:
    #include<iostream> 
    02 using namespace std; 
    03 
    04 struct record 
    05 { 
    06 double quiz1; 
    07 double quiz2; 
    08 double midyear, midyear_one; 
    09 double final, final_one; 
    10 double quiz_average; 
    11 char final_grade; 
    12 double total_grade; 
    13 }; 
    14 void instructions(); 
    15 void input(record& the_grades); 
    16 void output(record& the_grades); 
    17 
    18 int main() 
    19 { 
    20 record grades; 
    21 instructions(); 
    22 input(grades); 
    23 output(grades); 
    24 cout << endl << endl; 
    25 cout << "<program end>"; 
    26 cout << endl << endl; 
    27 system("pause"); 
    28 return 0; 
    29 } 
    30 
    31 void instructions() 
    32 { 
    33 cout << "Welcome to the program student record"; 
    34 cout << endl << "this program takes in 2quizes, a final and midyear"; 
    35 cout << endl << "and then calculates the average by what they are worth by"; 
    36 cout << endl << "the quizes together are worth 25% and midyear counts for 25%"; 
    37 cout << endl << "and the final counts for 50%"; 
    38 cout << endl; 
    39 } 
    40 void input(record& the_grades) 
    41 { 
    42 cout << "Enter quiz1 grade out of 10 points:\n"; 
    43 cin >> the_grades.quiz1; 
    44 cout << endl; 
    45 cout << "Enter quiz2 grade out of 10 points:\n"; 
    46 cin >> the_grades.quiz2; 
    47 cout << "Enter midyear Exam grade out of 100 points:\n"; 
    48 cin >> the_grades.midyear; 
    49 cout << endl; 
    50 cout << "Enter Final Exam grade out of 100 points:\n"; 
    51 cin >> the_grades.final; 
    52 cout << endl; 
    53 } 
    54 void output(record& the_grades) 
    55 { 
    56 the_grades.quiz_average = (((the_grades.quiz1/10) + (the_grades.quiz2/10))/2) * .25; 
    57 the_grades.final_one = (the_grades.final/100) * .5; 
    58 the_grades.midyear_one = (the_grades.midyear/100) *.25; 
    59 the_grades.total_grade = the_grades.quiz_average + the_grades.final_one + the_grades.midyear_one; 
    60 
    61 cout << endl << endl;
    62 cout <<"Quiz1: "<< the_grades.quiz1 <<"/10"; 
    63 cout << endl; 
    64 cout <<"Quiz2: "<< the_grades.quiz2 <<"/10"; 
    65 cout << endl; 
    66 cout <<"Midyear exam: " << the_grades.midyear<<"/100"; 
    67 cout << endl; 
    68 cout <<"Final exam: " << the_grades.final<<"/100"; 
    69 cout << endl; 
    70 cout <<"Final grade: "<< the_grades.total_grade*100; 
    71 cout << endl; 
    72 cout <<"Letter grade: "; 
    73 if(the_grades.total_grade < 60) 
    74 { 
    75 cout << "F"; 
    76 } 
    77 if((the_grades.total_grade > 60)&&(the_grades.total_grade < 70)) 
    78 { 
    79 cout << "D"; 
    80 } 
    81 if((the_grades.total_grade > 70)&&(the_grades.total_grade < 80)) 
    82 { 
    83 cout << "C"; 
    84 } 
    85 if((the_grades.total_grade > 80)&&(the_grades.total_grade < 90)) 
    86 { 
    87 cout << "B"; 
    88 } 
    89 if(the_grades.total_grade > 90) 
    90 { 
    91 cout << "A"; 
    92 } 
    93 cout << endl; 
    94 
    95 
    96 }
    Last edited by anlk5910; 10-11-2011 at 08:49 AM. Reason: changing

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well you could edit your post so that your code isn't double-numbered and double-spaced.

    Then people will be more inclined to read it.
    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.

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    3
    Quote Originally Posted by Salem View Post
    Well you could edit your post so that your code isn't double-numbered and double-spaced.

    Then people will be more inclined to read it.
    done it

  4. #4
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by anlk5910 View Post
    done it
    Sooooo..... eerrrrrr

    You might want to post the new code without all the numbers and with the proper indentation, just so, you know, we can see it?
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > cout <<"Final grade: "<< the_grades.total_grade*100;
    What does this print?
    And what does that mean for the original value of total_grade, when it comes to all your comparisons.

    BTW, what happens if you have == 80 for example?
    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.

  6. #6
    Registered User
    Join Date
    Oct 2011
    Posts
    3
    I figured it out

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Share your answer so the rest of the world might benefit from your knowledge.
    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.

  8. #8
    Registered User
    Join Date
    Oct 2011
    Posts
    1
    It seems the maximum your total grade sum can be is 1, so try dividing the testing conditions by 100.

    This code in particular needs to be changed,

    cout <<"Letter grade: ";
    73 if(the_grades.total_grade < 60)
    74 {
    75 cout << "F";
    76 }
    77 if((the_grades.total_grade > 60)&&(the_grades.total_grade < 70))
    78 {
    79 cout << "D";
    80 }
    81 if((the_grades.total_grade > 70)&&(the_grades.total_grade < 80))
    82 {
    83 cout << "C";
    84 }
    85 if((the_grades.total_grade > 80)&&(the_grades.total_grade < 90))
    86 {
    87 cout << "B";
    88 }
    89 if(the_grades.total_grade > 90)
    90 {
    91 cout << "A";
    92 }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having problem with a program for Calculating Grades
    By Magmadragoon in forum C Programming
    Replies: 17
    Last Post: 02-15-2011, 08:21 AM
  2. calculating gpa with only grades?
    By ashlee in forum C Programming
    Replies: 8
    Last Post: 11-03-2010, 10:18 AM
  3. Grades
    By ksample23 in forum C Programming
    Replies: 7
    Last Post: 04-01-2010, 08:20 AM
  4. Calculating grades
    By Ducky in forum C++ Programming
    Replies: 0
    Last Post: 03-14-2008, 12:16 AM
  5. Replies: 13
    Last Post: 08-15-2002, 09:20 AM

Tags for this Thread