![]() |
|
#1
|
|||
|
|||
Math problem: Total NoobHello. I'm taking a C course right now and I'm stumped.. I can't figure out why my code isn't working.
Here is my homework assignment: (no I'm not looking for anyone to do this for me.. and please be kind. It's my first C course) 1) present a menu to the user from which there will be 6 choices A -> Add two numbers S -> Subtract two numbers M -> Multiply two numbers D -> Divide two numbers O -> Modulus two numbers E -> Exit 2) If the user enters a A, S, M, D or a O the program will prompt the user for two numbers and perform the needed math on them and output the number. 3) If the user enters an E then the program will thank the user for trying to use the program then exit nicely. 4) The program must use If ?else statements. 5) The program should use floating point numbers for all numbers entered. But you must cast them to an integer for the modulus. I'm stumped on the casting, but I'll worry about that later. This is my code snippet: CPP / C++ / C Code:
When I compile and run this every answer I get is: The total is 0.000000, &result Obviously I have something boneheaded in there.. and I've got 4 books and Google and no idea what I missed. Can someone help me? Thank you! Jennifer |
|
#2
|
||||
|
||||
Re: Math problem: Total NoobJennifer, THANK YOU for reading the Guidelines before posting! You are a pearl in the .... better stop there
First thing you should always do when you run up against a problem like this is print the values entered to see if they are correct. You may find they aren't. scanf() is a notoriously ill-behaved function, and I think you might be getting caught in the dirty-input-stream problem. See this. Also, since all your operations work on 2 numbers, you could read the numbers before your IFs and have only one place for reading. But if you plan on accepting 1 or 3 numbers at some point, this may not be a good thing to do. [edit]I just noticed your printf() for the result is wrong. Look carefully.[/edit] __________________
Age is unimportant -- except in cheese |
|
#3
|
|||
|
|||
Re: Math problem: Total NoobAnd now to solve your problem:
Code:
should be: Code:
(I replaced the quote) Just a tiny syntax error! gr Niek |
|
#4
|
|||
|
|||
Re: Math problem: Total NoobQuote:
Waltp, Nothing annoys me more than people who don't. I also think I'm going to tape RTFM on my wall at my desk at work.. But thank you. Quote:
Thanks niek_e! That would be the "boneheaded" piece I couldn't find! Quotes always goof me up. You should have seen me trying to teach myself html! |
Recent GIDBlog
Meeting the populace by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Runtime Problem involving "printf" in C Program | supamakia | C Programming Language | 2 | 09-Oct-2005 10:09 |
| Problem with DocumentRoot with apache 2.0 on Red Hat Linux(im a noob) | vjender | Apache Web Server Forum | 0 | 21-Aug-2005 05:05 |
| a significant problem after installing Xp | mohammad | Computer Software Forum - Windows | 10 | 09-Aug-2005 07:03 |
| Hash table problem. | penance | C Programming Language | 1 | 24-Jul-2005 18:50 |
| Small problem | Krc784 | C++ Forum | 1 | 05-Nov-2004 08:34 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The