|
-
Jan 16th, 2001, 07:33 PM
#1
Thread Starter
Registered User
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.
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 
Note: Compiler i'm using is DevC++ its a GUI
-
Jan 16th, 2001, 07:43 PM
#2
Frenzied Member
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)
Code:
#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;
}
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Jan 16th, 2001, 08:06 PM
#3
Thread Starter
Registered User
Thanks~
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, 09:01 PM
#4
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:
Code:
#include <iostream>
int main()
{
std::cout << "hello";
return 0;
}
you could do:
Code:
#include <iostream>
using std::cout;
int main()
{
cout << "hello";
return 0;
}
but you would still have to use:
so you would just use the whole namespace:
Code:
using namespace std;
-
Jan 17th, 2001, 05:10 PM
#5
Thread Starter
Registered User
hey thanks for all your help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|