![]() |
|
#1
|
|||
|
|||
Issues converting Fahrenheit to celcius [was: ok another one blowing my mind ...]/*The code below was taken straight from Sam's book for demonstrating the use of local variables and parameters. Is supposed to convert Fahrenheit to celsius. Doesn't work though, keeps bailing out after first number is entered in program. I wrote it using my own method in code as seen below this this and seems to work fine converting the temperature both ways using the correct math. I'm glad it works and is more useful using my method but, I think I'm not learning the point by getting creative here. Any ideas why the book style doesn't work*/
CPP / C++ / C Code:
CPP / C++ / C Code:
Last edited by JdS : 08-Mar-2004 at 05:56.
Reason: Please use a better title in your thread
|
|||
|
#2
|
||||
|
||||
|
Skampy, the reason the first version bails out after the number is entered is not an error. The program successfully completes its job, then exits. Try adding your system("pause"); at the end of the first version, before the return 0; part.
|
|
#3
|
|||
|
|||
many thanks that is partially workingthe program now gives the celsius temp then the press to continue option and bails. Based on the textbook this is supposed to be the output:
Please enter the temperature in Fahrenheit: 212 Here's the temperature in Celsius: 100 *now i'm getting the press to continue and it exists. *the rest of these i'm not seeing even after I tried adding the system pause in the second function as well Please enter the temperature in Fahrenheit: 32 Here's the termperature in Celsius: 0 Please enter the temperature in fahrenheit: 85 Here's the temperature in Celsius: 29.4444 *maybe could be my compiler i guess Quote:
|
|
#4
|
||||
|
||||
|
Hi Skampy.
One thing real quick that helps a ton when you post code. If you place [c] before your code and [/c] after your code, it will be highlighted as I have editted above. I think that it is great that you are experimenting with different ways to do things in C/C++. The book was probably trying to show the use of functions. Functions are the key to good programming (IMHO). Anyway, it appears that you got it to work both ways. |
|
#5
|
||||
|
||||
|
Quote:
CPP / C++ / C Code:
|
|
#6
|
|||
|
|||
Re: Issues converting Fahrenheit to celsiusHey, I was having the same problem... But there is a solution. Its Simple too.
all you have to do is open you're command prompt (start/run/cmd) and click and drag your compiled file into it then press enter... It will run it and not kill it's self after you press a key. Hope I helped. |
|
#7
|
||||
|
||||
Re: Issues converting Fahrenheit to celsiusQuote:
![]() __________________
During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence? |
|
#8
|
||||
|
||||
Re: Issues converting Fahrenheit to celsiusReally, it doesn't matter how old this (or any other) thread is.
What matters is that any new posts / replies appended to it are relevant, up to date, and/or useful. If it's not, just say so or better yet, use the "Report Bad Post" button to have them (useless posts) deleted. |
|
#9
|
|||
|
|||
Re: Issues converting Fahrenheit to celsiusI need to do the same.
I'm almost finished, but I got another problem. Additionally I want to round up or down the Celsius answer by adding 0.5 to the calculation expression. I'm new to this, so I am not quite sure how to do this. Can someone help me? Also ,I don't understand why I am supposed to add 0.5... how is that gonna round it up or down?? |
|
#10
|
||||
|
||||
Re: Issues converting Fahrenheit to celsiusThe reason you add 0.5 is because converting a floating point number to an integer will truncate the value. 1.2 becomes 1, 3.6 becomes 3, 5.999 becomes 5.
So if you have 4.7, truncating gives you 4 but you clearly want 5 when rounding. Therefore add 0.5 first. You now have 5.2 which becomes 5. And why 0.5? Because any number below x.5 rounds to x. Any number equal to or greater than x.5 rounds up to x+1. __________________
During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence? |
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| newbie using Sam's series | Skampy | C++ Forum | 3 | 06-Mar-2004 19:51 |
| (read/write file) newbie need help plz | momotx | C Programming Language | 6 | 28-Jan-2004 14:40 |
| Newbie help with unary ops | Tony | C Programming Language | 2 | 04-Jan-2004 20:10 |
| newbie help | milwalt | C++ Forum | 1 | 27-Dec-2003 12:52 |
| total newbie need help | grunt123 | Apache Web Server Forum | 2 | 04-Dec-2003 12:14 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The