July 7th, 2002, 08:50 AM
|
#1 (permalink)
| | Ultimate Member
Join Date: Dec 1969
Posts: 1,411
| Need help with C programming
i'm just wanting to compile a C program that was part of my homework using Borland Uber-Crappy-Commandline C Compiler (tm).
I type bcc32 d:\borland\bcc55\temp.cpp to compile the .cpp file and it gives me "8: Declaration Terminated Incorrectly"
the line it refers to is:
float fahr;
(its in a program to convert temperature in fahrenheit to centigrade and i'm declaring the "fahr" variable)
I wouldnt be surprised if its me that has monked up the use of FLOAT.
the whole program is:
#include <iostream.h>
#include <iomanip.h>
{
float fahr=0;
float cent=0;
cout<<"Temperature in Fahrenheit =\n";
cin>>fahr;
cent =(fahr-32)*(5/9);
cout<<"";
cout<<setprecision(2)<<F<<" degrees Fahrenheit is the same as "<<Cent<<" degrees Celcius\n";
return 0;
}
and if i've fadged something up then someone pls say.  |
| |
July 7th, 2002, 08:54 AM
|
#2 (permalink)
| | Ultimate Member
Join Date: Dec 1969
Posts: 1,411
|
W00t never mind.
I messed that program up royally, and just realised now.
forgot int main(), and fadged up references to the fahr variable by calling it F (which it was before).
ok, nm thanks |
| |
July 7th, 2002, 09:17 AM
|
#3 (permalink)
| | Ultimate Member
Join Date: Dec 1969
Posts: 1,411
|
okay, i do actually need help. When i try to compile i get 'cent' is assigned to a value that is never used in function main()
the program is now:
#include <iostream.h>
#include <iomanip.h>
int main()
{
float fahr;
float cent;
cout<<"Temperature in Fahrenheit =\n";
cin>>fahr;
cent = (32-fahr)*(5/9);
cout<<"Temperature in celcius is:\n"
cout<<setprecision(2) << cent<< endl;
return 0;
}
hmm cent is actually used so i dont know what the hell it means...
help...? |
| |
July 7th, 2002, 07:48 PM
|
#4 (permalink)
| | Senior Member
Join Date: Oct 2001 Location: Alberta, Canada
Posts: 563
|
either you goofed when you copied the code to your last post, or you have an error at this line: cout<<"Temperature in celcius is:\n"
needs a semi-colon at the end. but, if thats where the error is from, that sure is a mis-leading error message!!
cheers!  |
| |
July 8th, 2002, 01:37 AM
|
#5 (permalink)
| | Senior Member
Join Date: Oct 2001 Location: Eastern Shore
Posts: 701
|
Borland, for some reason, loves to give those "never-used" messages alot. Normally they are just warnings, and not actually errors though. I think ^hyd^ solved your problem though, i can't find anything else wrong with it.
ILC |
| |
July 8th, 2002, 01:11 PM
|
#6 (permalink)
| | Ultimate Member
Join Date: Dec 1969
Posts: 1,411
|
heh i added the semi colon, the program now compiles...but gives me the answer "-0" for everythin I put in.
I think its the maths thats fscking things up, the way i've written it. |
| |
July 8th, 2002, 04:15 PM
|
#7 (permalink)
| | Senior Member
Join Date: Oct 2001 Location: Alberta, Canada
Posts: 563
|
might be because of integer division. try this:
cent = (32.0-fahr)*(5.0/9.0);
ciao! |
| |
July 8th, 2002, 05:07 PM
|
#8 (permalink)
| | Ultimate Member
Join Date: Dec 1969
Posts: 1,411
|
almost worked, all temperatures are the negative of what they should be...
-edit- nm i got it sorted (fahr-32) instead of (fahr-32)
w00t, thanks for the help  |
| |
July 8th, 2002, 07:33 PM
|
#9 (permalink)
| | Senior Member
Join Date: Oct 2001 Location: Alberta, Canada
Posts: 563
|
np!
but... what's the diff: "(fahr-32) instead of (fahr-32)"  ... guess it doesn't matter if you say it's working!!
cheers! |
| |
July 8th, 2002, 07:57 PM
|
#10 (permalink)
| | Ultimate Member
Join Date: Dec 1969
Posts: 1,411
|
lol
i mean (fahr-32) instead of (32-fahr)
i guess i was just so darn excited i could convert from fahrenheit to celcius...  |
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |
Posting Rules
| You may post new threads You may post replies You may not post attachments You may not edit your posts HTML code is Off | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |