![]() |
|
#1
|
|||
|
|||
Convert Fahrenheit to Celsius and Kelvinmy assignment is to write a program that asks for a temperature in fahrenheit, then spits out a value in celsius and kelvin. and ask again for a value in fahrenheit to convert. heres what ive got so far. by the way im using kernhigan and ritchie, with no experience in programming whatsoever. im finding that kernhigan and ritchie is not very good for me.
CPP / C++ / C Code:
also, my next assignment is to use the program above (when written correctly) and rewrite it so that it uses one function to conver from fahrenheit to celsius and another to convert from celsius to kelivin. any help would be appreceated Last edited by LuciWiz : 24-Apr-2006 at 06:00.
Reason: Please insert your C code between [c] & [/c] tags; Edited title (previous title was "newb question: probs with following program")
|
|
#2
|
|||
|
|||
Re: newb question: probs with following programQuote:
I have heard a number of people say that, and I won't argue about what's best for you or anybody else. If you poke around on the web or at a bookstore you might find something more to your liking. In the meanwhile... You can't make up your own language: the "R" of K&R created the language, and you have to play by the rules. Look at examples of K&R and try to make yours look like the ones there. Type some of them into your computer and compile them. If something happens that you don't understand, then ask us about it. Now for your program: CPP / C++ / C Code:
< stdio.h > might not work, but <stdio.h> surely will (assuming your compiler is properly installed on your system). So the very first line has two errors. What did your compiler say when you gave your program to it? When asking for help, here is the suggestion: Show us (exactly) what messages the compiler gave you that you don't understand. Be precise: post the entire message into your post; don't paraphrase. Tell us what compiler you are using. Sometimes it makes a difference to people who are trying to help you. Now, go back and clean up your program and try to get it to compile. If the compiler tells you something, read the message and see if it means something to you. Sometimes cleaning up the problem that caused the first message will make some of the others go away. So, if your compiler says Code:
Note that if you fix line 1, then some of the other messages will go away: Code:
All of these are caused by the compiler not being able to get the information that line number 1 was supposed to convey. I know that this is all very obscure for people who have never tried such a thing before, but it's a learning process, right? (No one was born knowing this stuff, you know.) My point is: try to understand. If you don't understand, then ask. There are a lot of very capable people here who are not only willing, but eager to help. Some of us even remember what it was like trying to get started! So: the first step is to get the program to compile with no errors. (I strongly suggest that you eliminate warning messages as well as errors. At this point in the game, you don't know whether a warning is serious or not, so just get rid of 'em all, I say.) Now, when the program compiles OK, the real fun begins: You should be able to see some output from the program. If it's not what you expect it to be, then you enter phase II: debugging. Remember, you can't make up your own rules for usage any more than you can make up the rules for syntax. Look in K&R (or other resources) for examples of reading numerical values. Hint: getc() is not what most people would recommend at this point. Regards, Dave |
|
#3
|
|||
|
|||
Re: newb question: probs with following programQuote:
CPP / C++ / C Code:
Output: Code:
Take a closer look at your conversion formulas... CPP / C++ / C Code:
...should be: CPP / C++ / C Code:
Also, cels and kelv should be floats, not ints, unless you want the value truncated! :davis: |
Recent GIDBlog
Meeting the local Iraqis by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The