# Thread: Newbie at programming (for now) and in need of help

1. ## Newbie at programming (for now) and in need of help

I'm relatively sucky at programming and I don't even know where to begin on this assignment I have due. If anyone can help it would be much appreciated.

C programming.

Write a C program that defines and tests a function for converting Fahrenheit temperatures to Celsius. Your program should include three functions:

* A conversion function to perform the actual conversion. This function should take one parameter, a double representing a Fahrenheit temperature, and return the equivalent Celsius temperature as a double. (So, for example, your_function(32) should return 0.)

* A convert-and-print function that calls the conversion function and prints its input and output nicely -- for example:

32 degrees Fahrenheit is 0 degrees Celsius

(Don't worry too much about printing appropriate numbers of digits after the decimal point; you can do whatever is easy, or read the man page or other documentation for printf to find out how to get more control.)

* A main function that calls the convert-and-print function at least four times with different inputs that you think will illustrate that the conversion is working right. (So this program is self-contained and doesn't prompt the user for anything!)

I'm good with loops, but this program requires recursion which I'm terrible at. Thanks all

2. So, can you please clarify what you have done so far, and where you are stuck? This forum is not "post your assignment and we write it for you", it is "you do the work, we help you out when you are stuck or don't understand how it works".

--
Mats

3. jus get the formula to convert fahrenheit to celsius ...

4. you dont need recursion on this code you even on main u could make it...

5. sorry about that. well the thing is, i'm having a hard time visualizing how this is done. i think i understand it conceptually not, but there's no guarantee about my program. i'll post it later today.

6. okay this is what i have so far and its getting screwy with me.
Code:
```#include <stdio.h>

double convertFahrenheit(void)
double convertPrint(void)

int main(void)
{
convertPrint(temp);

}

double convertFahrenheit(void)
{
double number;
double celsius;

celsius = ((number-32)*(5/9));

return celsius;
}

double convertPrint(temp)
{
double temp;
temp = 212;
printf("Your number %d", temp);

return temp;
}```
what im trying to do is get convertPrint to call convertFahrenheit (which i don't exactly know how to do). and then get the main function to call convertPrint (as shown from the criteria above). i tried doing a small run through with one number (212, boiling point), but i'm getting some syntax errors. input?

7. Without reading your question, or intent I see something wrong.

Code:
```double convertFahrenheit(void)
{
double number; <--- NOT INITIALIZED! Should be a parameter!!!
double celsius;

celsius = ((number-32)*(5/9));

return celsius;
}

double convertPrint(temp) <-- What the hell?? You need a type
{
double temp;
temp = 212;
printf("Your number &#37;d", temp);

return temp;
}```
Change those to 32.0, 5.0, and 9.0, respectively.

8. Remember, 5/9 is 0. Also remember, you have to give the types of the parameters when you declare functions. And, your prototype at the top and the actual function at the bottom have to agree as to the function parameters. Too, to call a function you type its name followed by a set of parentheses (which contain the arguments you want to pass).

9. Originally Posted by tabstop
Remember, 5/9 is 0. Also remember, you have to give the types of the parameters when you declare functions. And, your prototype at the top and the actual function at the bottom have to agree as to the function parameters. Too, to call a function you type its name followed by a set of parentheses (which contain the arguments you want to pass).
tabstop is like a tactful version of me at times

10. redux, that program was obviously bad, this is what i have currently...

Code:
```#include <stdio.h>

double convertFahrenheit();
double convertPrint();

int main(void)
{
convertPrint(212);

return 0;
}

double convertFahrenheit()
{
double number;
double celsius;

celsius = (((number-32)*5)/9);

return celsius;
}

double convertPrint()
{
double temp;

temp = convertFahrenheit();
printf("Your tempurature in Fahrenheit is %lf", temp);

return temp;
}```
what i want it to do is convert convertPrint(212) into celsius. then put convertPrint(32) and other types of fahrenheit degrees calculated.......but it's not quite there yet....

11. Ok bud, I think you are having trouble with your understanding of functions. Do pay attention to my remarks about using 32.0 (the .0 is not trivial).

Example:
Code:
```double convertFahrenheit(double number)
{
double celsius;

celsius = (((number-32.0)*5.0)/9.0);

return celsius;
}```
Similar should be done for the other function. It currently has no parameter, yet it should have one.

12. actually it works in other programs without the .0, so it really isn't the problem. what i'm trying to do is get the main function to call convertPrint which calls the convertFahrenheit equation. and when i put that 212 in the main, i wanted it to go through convertPrint which goes through convertFahrenheit to convert the 212 into 100 celsius. problem is the code doesn't work....

13. The way you have it now is all well and dandy since it will implicitly convert to doubles. In any event, I bolded the concept I was mostly trying to get you to focus on.

And if you explicitly tell the compiler what you want, you can at least do things like this.

Code:
`    celsius = ((number-32)*5.0/9.0);`

14. i inputted your .0's but still no dice. what it executes is....

Your temperature in Celsius is -17.7777778

the answer's suppose to be 100 celsius. still no idea why convertPrint(212) doesn't take 212 through the convertFahrenheit equation.

15. Again... bolded thing is a clue.... I don't have time to play games as I am running late for class...

Code:
```double convertPrint(double temp)
{
temp = convertFahrenheit(temp);
printf("Your tempurature in Fahrenheit is &#37;lf", temp);

return temp;
}```

Popular pages Recent additions