![]() |
|
#1
|
|||
|
|||
Temperature Conversion ErrorHello, I have just started my Introduction to C programming course out at UCF, and I was wondering if some of you would be able to give some help.
I'll paste the basic assignment details: Problem A: Temperature This program will convert between Fahrenheit and Celsius. The information you will collect from the user is: 1. Magnitude of the temperature 2. Type of measurement Prompt the user to input these values. You will output a single statement showing both original and converted temperature values (as rounded integers). Input Specification 1. Magnitude of the temperature is an integer and the program will read it into an integer variable (even though it would be possible to read it into a floating point variable, why am I enforcing this?). 2. Type of measurement is a single lowercase character, which will be used to determine the type of the temperature entered. For example, if the user enters “123 f”, this means 123 is in Fahrenheit and it needs to be converted to Celsius. Output Sample You should test your program with different data than is shown here based on the specifications given. The user input is given in italics while the program output is in bold. Sample Run 1 Enter the temperature and type: 26 c Converting from Celsius to Fahrenheit… The formula is F=(9/5)*C+32 26 Celsius is 79 Fahrenheit. Sample Run 2 Enter the temperature and type: 78 f Converting from Fahrenheit to Celsius… The formula is C=(5/9)*(F-32) 78 Fahrenheit is 26 Celsius. I'll start off with the code: CPP / C++ / C Code:
The problem that I'm having is with the equations. The rest of this program seems to complie, link, and run perfectly fine. However, when I enter the input to be converted, it always returns '0' for the answer. I'm sure that the problem lies in my equations. If you find anything else that could be a problem, please let me know. This is my first time learning C and I'm really avid on learning the ins and outs of it all. Thanks in advance! Looking forward to your replies! |
|
#2
|
||||
|
||||
Re: Basic C programming errorSince you take temperature as a 'float' type, use %f in your printf's instead of %d.
Or if you keep %d, you'll have to cast your printf expressions to 'int', i.e. (int)( your expression ). __________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! |
|
#3
|
|||
|
|||
Re: Basic C programming errorEDIT: I got it working now. Thanks! I had my math equations down wrong. I just misplaced the parenthesis is all.
Thanks for the help on the decimal placement for the answer by the way. |
|
#4
|
||||
|
||||
Re: Basic C programming errorGood,
I was going to ask about that calculation.__________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! |
|
#5
|
||||
|
||||
Re: Basic C programming errorHey Cecil, could you post your working code? I have a problem with what you posted that TurboPT didn't point out, and wondered if you fixed it.
Also, your formatting is a little horizontal heavy. Check out the Formatting code tutorial for different ideas. __________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#6
|
|||
|
|||
Re: Basic C programming errorCertainly, here is the working code:
CPP / C++ / C Code:
|
|
#7
|
||||
|
||||
Re: Basic C programming errorOK, you fixed the problem I saw, but IMO you fixed it wrong.
CPP / C++ / C Code:
CPP / C++ / C Code:
#2) You shouldn't set the value of temperature in the printf() __________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#8
|
|||
|
|||
Re: Temperature Conversion ErrorAh, very nice observation. Thanks for the help!
|
|
#9
|
|||
|
|||
Re: Temperature Conversion Errorthis is interesting, ive seen similar issues.
__________________
Hosting Definitions http://www.***.com/gl/ Trust me, they'll help |
Recent GIDBlog
Python ebook by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Winsock error when compiling FLTK 2.0 Projects | mauriciorossi | FLTK Forum | 3 | 16-Aug-2005 11:18 |
| Help with syntax errors | PeteGallo | C Programming Language | 7 | 08-Aug-2005 21:30 |
| What is "Ambigious symbol" ??*( a compilation error) | small_ticket | C++ Forum | 2 | 07-Jan-2005 22:10 |
| Error C2146: syntax error : missing ',' before identifier 'C4' | mattchew008 | C++ Forum | 2 | 19-Dec-2004 07:06 |
| Can enum have same name as class? | crystalattice | C++ Forum | 3 | 08-Dec-2004 17:43 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The