![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Can someone please help me understand why this won't work right?I don't quite understand why this won't work. Also we are not using arrays or functions other than main. were just into the basics and starting to cover things in <iomanip> and such. Thanks in advance.
CPP / C++ / C Code:
Last edited by admin : 15-Feb-2009 at 23:41.
Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
|
|||
|
#2
|
|||
|
|||
Re: Can someone please help me understand why this won't work right?Quote:
1. What input did you give to the program? 2. What did you expect to see from the program? 3. What output did the program give you? 4. What do you not understand about the difference betwee, (2) and (3)? Regards, Dave |
|
#3
|
|||
|
|||
Re: Can someone please help me understand why this won't work right?Well I started by giving the first input a letter A and from there it displays every line of 'cout' and calculates nothing. The program should let me input 2 letter grades and 2 credit hour values and from there it should calculate the GPA, instead like I had said it only lets me input the first letter grade and after I press enter it displays every cout line of code and the program waits for me to end it. So I'm not sure why after I input one value and press enter why it runs through every line of code, displaying the ones it should but never let me input anything past the first and it calculates nothing.
|
|
#4
|
|||
|
|||
Re: Can someone please help me understand why this won't work right?This is the output.
Please enter letter grade of first class --> A Please enter number of credit hours for first class --> Please enter letter grade of second class --> Please enter number of credit hours for the second class --> Press any key to continue... Note, after the first value is inputed and the enter key is pressed, the program displays what you see above and leaves everything blank and waits for the program to be ended. |
|
#5
|
|||
|
|||
Re: Can someone please help me understand why this won't work right?Quote:
Huh??? You have this: CPP / C++ / C Code:
Your so-called "letter grade" variables are double precision floating point variables, so you will have to give it numbers. If you enter a non-numeric quantity, the input stream (cin) enters a "Fail" state, and it can not be used for anything else until it is cleared. The result is that further attempts to use "cin>>" will fail (that is, the "cin>>" will return to the program without reading anything from the user). Also, for debugging purposes, I would probably print out values that were entered and other intermediate calculations. Something like; CPP / C++ / C Code:
A run might look like: Code:
Of course, after debugging, you might remove any output statements that are not part of the assignment. Also, I probably wouldn't ask the user to enter a "letter grade" if the program requires a number, so I might change the prompts so that the user would have a clue as to what is expected. Regards, Dave |
|
#6
|
|||
|
|||
Re: Can someone please help me understand why this won't work right?Thanks, I did figure out that I was using the floating point instead of a character data type.
My next question is, since I have to have the user input either A, B, C, D, F, and the ASCII value for those are 65, 66, 67, 68, and 70, do I need to do a bunch of 'if' 'else if' statements. For example CPP / C++ / C Code:
Or can I somehow reasign a value to the character A to equal 4. I hope that I'm not being to confusing, and I really appretiate your help, but understand I'm new to this, but I want to learn, I love programming and I want to learn this stuff the right way. Again thanks for the help. Also I don't know how to use the debugger, if thats something you could explain to me that would be awesome. Thanks Dave |
Recent GIDBlog
Accepted for Ph.D. program by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Work at home. English proofreader needed. $14.50/hour | cascade_soft | Member Announcements, Advertisements & Offers | 0 | 05-Jun-2006 01:29 |
| Random access files | Krazy_yA | C Programming Language | 6 | 07-May-2006 02:44 |
| How do web redirection scripts work? | rhino1616 | Web Design Forum | 9 | 27-Oct-2003 10:47 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The