Temperature converter

So i've tried to create a program that takes in 10 numbers in celcius and displays them in fahrenheit and vice versa but i also have to have a controller function, ctof and ftoc function, this is what i got so far but cant get it to work


using namespace std;

int ftemps[10];
int ctemps[10];

int Controller();
int ctof(int);
int ftoc(int);
int t,x;

int main()
{ for(;;)
{ Controller();
} return(0);

int Controller()
{ int temps(x);
int char * fah;
int char * cel;
cout<<" Celcius to Farenheit (1) or Farenheit to Celcius (2)";
for(int x=0;x<10;x++)
{ cout<<"Give out one temperature: ";
if(temps == 0)
ctemps[x] = ctof(ftemps[x]);
ctemps[x] = ftoc(ftemps[x]);
} if(t==0)
{ fah = "Celcius: ";
cel = "Farenheit: ";
} else
{ cel = "Celcius: ";
fah = "Farenheit: ";
} cout<<"RESULTS";
for(int x=0;x<10;x++)
{ cout<<fah<<ftemps[x]<<" "<<cel<<ctemps[x]<<endl;
} return(0);

int ctof(int a)
{ return (a/5)*9 + 32;

int ftoc(int a)
{ return ((a-32)/9)*5;
First, please use code tags to post code (it's the <> button under Format to the right when posting or editing a post.)

In the first line of your Controller function you call a function called temps and pass x to it. First, there's no function definition for x. Also, you haven't even initialized or assigned a value to x, so its value is undefined. I'm going to assume though that you were actually trying to declare an array there? Unfortunately, arrays can only be declared with values known at compilation. If you want create one of a size that's only know at run time you will have to use either a dynamically allocated array (with the keyword new) or use another container type.

I'm not really sure why you have the controller function anyway. Most of that code could just as easily be contained in main. I usually try to keep functions as short and sweet as possible, and try to use them for one task and one task only, like your ctof and ftoc functions. Of course, that's personal preference. :)

The <iostream> header is included twice. Also, there is no type "int char*". The variables fah and cel don't do much, either. It seems you are trying to put too many things in Controller. Write 2 separate functions, inputData() (where you enter values in ctof and ftoc - notice that you are also using them as function names) and outputData() (for printing the converted values).
Topic archived. No new replies allowed.