Need some help,GPA program

This is a discussion on Need some help,GPA program within the C++ Programming forums, part of the General Programming Boards category; Ok, so I am writing a program that states your grade + GPA after you enter a grade and the ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    3

    Need some help,GPA program

    Ok, so I am writing a program that states your grade + GPA after you enter a grade and the course level. Using switches and if/else to do this, or trying. The GPA scale is as follows:
    Grade . Reg . Hon . AP
    97- 100 4.0 . 4.5 . 5.0
    94-96 . 3.7 . 4.2 . 4.5
    91-93 . 3.5 . 4.0 . 4.5
    87-90 . 3.3 . 3.8 . 4.5
    84-86 . 3.0 . 3.5 . 4.0
    81-83 . 2.7 . 3.2 . 3.7
    77-80 . 2.3 . 2.8 . 3.3
    75-76 . 2.0 . 2.5 . 3.0
    70-74 . 1.0 . 1.5 . 1.9

    So to accomplish this so far I have
    Code:
    #include <iostream.h>
    
    void main()
    
    {
    	int grade, level;
    	cout<< "What is your grade?";
    	cin>> grade;
    	cout<< "What type of class is it?\n1.) Regular\n2.) Honors\n3.) AP";
    	cin>> level;
    	int c=(grade>=97)+(grade>=94)+(grade>=91)+(grade>=87)+(grade>=84)+(grade>=81)+(grade>=77)+(grade>=75)+(grade>=70);
    
    	if(level == 1)
    	{
    		switch(c)
    		case 1:
    			cout << grade << " C "<<showpoint<<1.0<<endl;
    As you can tell the code is not finished, and I plan to switch on c with 12 cases that represent all 12 GPAs for each level of classes. I think this will work, but is there any way to shorten the code that I am not seeing using the same structure? I am pretty new to programming, and any help or suggestions would be appreciated. Thanks

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    First off, main() should return an int. It should not be void.

    Secondly, I think I speak for everyone when I say "What is this supposed to mean?"

    Code:
    int c=(grade>=97)+(grade>=94)+(grade>=91)+(grade>=87)+(grade>=84)+(grade>=81)+(grade>=77)+(grade>=75)+(grade>=70);
    When you set an int equal to a comparison, you end up with a boolean 1 or 0. When you assign it to 9 comparisons added together, you'd get a number between 1-9 depending on the value of grade. I don't think that's what you wanted. If it is, I'm not sure why, you said in your post that there is no GPA difference between 94 and 92.

    I'm also not getting the showpoint << 1.0. Are you just testing out what showpoint does or is that supposed to have a meaning?

    Other than that, you look alright so far. Just add a '\n' after AP, or better yet an endl. It doesn't look pretty when the user input appears right next to the output.
    Last edited by SlyMaelstrom; 11-12-2005 at 09:22 AM.
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    3
    First, void main() is just so you dont have to but a return 0; at the end of main, serves the same purpose.

    I used that second statement to help with the switch.. Otherwise I have no idea how to create the cases. It outputs 1 for each statement that is correct and 0 if incorrect. It adds them up and assigns to c so that a 100 would add up to 9 and would then go to case 9, which is a 4.0. a 0 would add up to 0 and go to case 0. A 70 would add up to 1 and be a 1.0. Etc...
    Showpoint i havnted checked what it actually outputed to look like, might need to change.
    Thanks for the help though, but you think that that would be the best way to go with how I am doing it?

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    First, void main() is just so you dont have to but a return 0; at the end of main, serves the same purpose.
    No it does not. There are many debates on this topic. With int main() you don't even need return 0 if you are concerned about space. main() returns zero by default (it's the only function that does so).

    'A' is much easier to read than 65.
    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
    Super Moderator Harbinger's Avatar
    Join Date
    Nov 2004
    Posts
    74
    > First, void main() is just so you dont have to but a return 0; at the end of main, serves the same purpose.
    Try reading the FAQ before you start spouting lots of "works for me" crap.
    Even your first line is "old school". If you compiler doesn't understand
    #include <iostream>
    Then get something more modern.

    Have you considered a table, and a loop?

  6. #6
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    http://users.aber.ac.uk/auj/voidmain.shtml

    Take a look at this. It's important.

    Also, I know what your assignment of c does, but it's the wrong way to go about it. Why shuffle through if statements and switches when you can easily pull everything out of an array with meaningful indexes.

    Create a 2d Array:
    Code:
     int GPA[31][3]  // That is to say GPA[grade - 70][classlevel]
                    // where 0 = CP  1 = Honors 2 = AP
    Then initialize your array with all of your values. Now all you have to do is check to see if grade is greater than 70. If it is, then output GPA[grade - 70][classlevel]. Nice and simple.
    Sent from my iPadŽ

  7. #7
    Registered User
    Join Date
    Nov 2005
    Posts
    3
    Well, sorry about the void main thing.. I read the page linked and found it an interesting read. Also thanks for the rest of the help I am fairly new to C++, as you can probley tell, but I will try to mess around with the arrays, see if I can get it to do what i want.

  8. #8
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Ok, if you haven't gotten into arrays, yet, then don't push yourself to learn them for this. It's best to do the program the best way you know how, then when you learn more you can change the program.
    Sent from my iPadŽ

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