I am writing a program that calculates GPA. The user needs to enter four different different data points to determine the GPA but my code is only reading the first user entry and then executing the rest of the program. How can I get it to continue asking for the rest of the input?
This program will determine your GPA for two classes.
Enter letter grade for first class --> B
Enter number of credit hours for first class -->
Enter letter grade for second class -->
Enter number of credit hours for second class -->
7.58306e-039 5411456
3.48432e-039 2486340
Your GPA = 6.29272e-039
Press any key to continue . . .
}}}}
As you can see, it is only letting me enter one grade and then automatically completes the rest of the program.
All your program sees when you input the grades is a "B", so your program will try to cram a "B" into a float variable (and fail).
The compiler pretty much boils away all variable names, so cin will never know whether or not you happened to have a variable named B in your code (and it probably doesn't care even if you do).
If it were possible to do something like this, you'd potentially end up with some strange results:
If cin were to look for a variable with the same name as my input, then if I were to enter "hello" into this program, should it print "hello" (which is the string I entered), or "goodbye" (which is the value of the hello variable)?