home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2963
Discussions: 188,378, Posts: 2,243,451, Members: 232,606
Old July 7th, 2002, 08:50 AM   Digg it!   #1 (permalink)
Ultimate Member
 
Lemon[H]ead's Avatar
 
Join Date: Dec 1969
Posts: 1,411
Send a message via AIM to Lemon[H]ead
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.

Lemon[H]ead is offline   Reply With Quote
Old July 7th, 2002, 08:54 AM     #2 (permalink)
Ultimate Member
 
Lemon[H]ead's Avatar
 
Join Date: Dec 1969
Posts: 1,411
Send a message via AIM to Lemon[H]ead
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

Lemon[H]ead is offline   Reply With Quote
Old July 7th, 2002, 09:17 AM     #3 (permalink)
Ultimate Member
 
Lemon[H]ead's Avatar
 
Join Date: Dec 1969
Posts: 1,411
Send a message via AIM to Lemon[H]ead
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...?

Lemon[H]ead is offline   Reply With Quote
Old 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!
^hyd^ is offline   Reply With Quote
Old July 8th, 2002, 01:37 AM     #5 (permalink)
ILC
Senior Member
 
ILC's Avatar
 
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
ILC is offline   Reply With Quote
Old July 8th, 2002, 01:11 PM     #6 (permalink)
Ultimate Member
 
Lemon[H]ead's Avatar
 
Join Date: Dec 1969
Posts: 1,411
Send a message via AIM to Lemon[H]ead
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.
Lemon[H]ead is offline   Reply With Quote
Old 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!
^hyd^ is offline   Reply With Quote
Old July 8th, 2002, 05:07 PM     #8 (permalink)
Ultimate Member
 
Lemon[H]ead's Avatar
 
Join Date: Dec 1969
Posts: 1,411
Send a message via AIM to Lemon[H]ead
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
Lemon[H]ead is offline   Reply With Quote
Old 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!
^hyd^ is offline   Reply With Quote
Old July 8th, 2002, 07:57 PM     #10 (permalink)
Ultimate Member
 
Lemon[H]ead's Avatar
 
Join Date: Dec 1969
Posts: 1,411
Send a message via AIM to Lemon[H]ead
lol
i mean (fahr-32) instead of (32-fahr)

i guess i was just so darn excited i could convert from fahrenheit to celcius...
Lemon[H]ead is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Most Active Discussions
Is It Just Me? (2883)
The United States Debt (20)
Looks like Burris will get his Sena.. (7)
I think I just killed my computer w.. (24)
Upgrading RAM (5)
Folderchat Weekday thread (439)
Antec 300 bulk purchase? (11)
Worth the upgrade?? (14)
Titan quest and Immortal Throne, an.. (17)
Recent Discussions
New Build ( Finally ) (1)
dual monitors wont boot (0)
Folderchat Weekday thread (439)
MSN Hotmail Down??? (7)
Help with an Ati Radeon HD 4850.. (23)
Laptop waking up itself (0)
CPU wont boot (3)
Best digital camera for under 2.. (13)
Building first computer, will t.. (2)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 08:18 PM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28