PDA

Click to See Complete Forum and Search --> : Hey i'm getting Errors on thsi simple Convert F to C app, Please help !


struntz
Jan 16th, 2001, 06:33 PM
Hello everyone!
i have been having troubles trying to compile this program, i ahve been getting around 10-12 errors i'll post the errors after the code.
#include <iostream.h>

float Convert(float);
int main()
{
float TempFer;
float TempCel;

cout <<"Enter a Ferienthite Degree.";
cout << "\n Ferienthite.\n";
cin >> TempFer;

TempCel = Convert(TempFer);
cout << "here is the temperature in Celcius: ";
cout << TempCel << endl;
return 0;
}

float Convert(TempFer)
{
float TempCel;
TempCel = ((TempFer - 32)*5) / 9;
return TempCel;
}



Errors:
c:\my documents\c++programs\day5\converttemp.cpp:19: `TempFer' was not declared in this scope
c:\my documents\c++programs\day5\converttemp.cpp:20: `float Convert' redeclared as different kind of symbol
c:\my documents\c++programs\day5\converttemp.cpp:3: previous declaration of `float Convert(float)'
c:\my documents\c++programs\day5\converttemp.cpp:20: syntax error before `{'
c:\my documents\c++programs\day5\converttemp.cpp:22: ANSI C++ forbids declaration `TempCel' with no type
c:\my documents\c++programs\day5\converttemp.cpp:22: `TempFer' was not declared in this scope
c:\my documents\c++programs\day5\converttemp.cpp:23: parse error before `return'

Can someone tell me what i'm doing wrong?
thanks for listening :D


Note: Compiler i'm using is DevC++ its a GUI

Technocrat
Jan 16th, 2001, 06:43 PM
Here first add using namespace std;
So you can get the correct library.

Second you need to tell what kind of var you are passing in function Convert. float Convert(float TempFer)



#include <iostream>

using namespace std;

float Convert(float);
int main()
{
float TempFer;
float TempCel;

cout <<"Enter a Ferienthite Degree.";
cout << "\n Ferienthite.\n";
cin >> TempFer;

TempCel = Convert(TempFer);
cout << "here is the temperature in Celcius: ";
cout << TempCel << endl;
return 0;
}

float Convert(float TempFer)
{
float TempCel;
TempCel = ((TempFer - 32)*5) / 9;
return TempCel;
}

struntz
Jan 16th, 2001, 07:06 PM
Hey thanks, it worked great!
but i didn't add using namespace std;

i heard thats an older way to get the libraries or somthing..whats up with that?
how do u know when to use "using namespace std;" and when to not use it?

Jan 16th, 2001, 08:01 PM
use:

using namespace std;

when you use the STL headers:


cstring
string
iostream
cstdio
cstdlib
cctype
ctime
algorithm
fstream


Note - None of those have the *.h extension

most platforms support <iostream>

I think windows is the only one that supports <iostream.h>


and the STL headers are enclosed in what is called a namespace, the particular one they are in is called std....
instead of using:


#include <iostream>

int main()
{
std::cout << "hello";
return 0;
}


you could do:


#include <iostream>
using std::cout;

int main()
{
cout << "hello";
return 0;
}


but you would still have to use:


srd::cin >> var;


so you would just use the whole namespace:


using namespace std;

struntz
Jan 17th, 2001, 04:10 PM
thanks!