I have to make a conversion table with two columns. The first with the word Celsius and its number is from -10 to 40. The second column with the word Fahrenheit. A function must be used to convert Celsius to Fahrenheit. Note : Give hints, do not post answers.
Here is my code.
#include <iostream>
using namespace std;
double Fahrenheit(int C, double F);
//Program display a conversion table from degrees Celsius to degrees Fahrenheit, using a function.
int main()
{
cout<<"Celsius"<<Fahrenheit(-10,39.6);
cout<<endl;
cout<<"Fahrenheit"<<Fahrenheit(-10,39.6);
cout<<endl;
system("pause");
return 0;
}
double Fahrenheit(int C, double F)
{
do
{
F=(9/5)*C+32;
F++;
C++;
} while (C<=40);
return F;
return C;
}
I understand what you need to make. How can somebody give you hints and not answers if you do not let them know where and what specifically are tripping you up?
One quick suggestion would be to take the Fahrenheit function out of your main function and move it above the main function.
Also for your output do you want a horizontal table or a vertical table? What you have now will not give you what you want but it would help us if we knew what you wanted so we can assist you better.
- You only need one parameter for your function. Declaring the 'f' variable inside the function would work a lot better, so you don't have to put in something meaningless every time you call it.
- You need to declare the 'c' variable as 'double' type; otherwise, you will have to cast.
- You can't return two different values from a function. You could create a global variable, and tell the function to put the Celsius value into it, so you can use it later.
you don't even need any parameters inside the function. just do double Fahrenheit()
have your Fahrenheit function do a for loop from -10 to 40 iterating C up one after each loop and have it output C and F after each loop. In fact your Fahrenheit function should just be void Farenheit() , as you have stated the problem you do not need to be returning any values, just outputting them to build a table, why make it more difficult than it needs to be?
Your output should be in the function and come after you calculate the F. Also if you need columns then you need to rethink how you are outputting and where/when to use cout<<endl; , what you have currently will not get you columns.