Firstly, please indent code for readability, and use the code tags (see the Announcement about BB tags)
You write the conversion functions, but never use them. You need to put curly braces { } around the code that makes up each if block. You cannot put the calculation for temp conversion inside the double quoted string text, the expression must be a separate output action. But, you should be using your function, not doing the work inline. So here's a fixed up bit:
if (choice == 1)
{
cout << "Enter the temperature in degree F to convert: ";
cin >> temperatureF;
cout << "The temperature you have entered in F," << temperatureF << "is "
<< FahrenheittoCelsius( temperatureF ) << " Celsius" << endl;;
}
Last comment (for now) - your division of 9/5 will not give you correct results. Remember that division of integers gives an integer result, 1 in this case. Change one or both operands to a floating point value for the accuracy you need. Then you'll need to do some typecasting of the final result back to int to satisfy your function's return type.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
I refuse to read your code until it's properly formatted.
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
Like Joe, I shouldn't respond till you format better (INDENT).
Choice 2 - do I get to enter some temp to be converted?
Choice 3 - you declare a variable there, which is masking the one of the same name that you really meant to use to halt the loop.
No more help till your code is more readable.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
Check out this link on how to do it (I'm linking rather than showing you myself because I myself haven't figured out how to make it display the words "code=C++" and "/code" as text without it getting interpreted as code).
http://www.daniweb.com/forums/post535004-2.html
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
Check out this link on how to do it (I'm linking rather than showing you myself because I myself haven't figured out how to make it display the words "code=C++" and "/code" as text without it getting interpreted as code).
Use the noparse tag. E.g.[noparse][code=c++] code goes here[/code][/noparse]
Turns into
[code=c++] code goes here[/code]
To show the noparse tag in your post, use another noparse tag.[noparse][noparse][code=c++] code goes here[/code][/noparse][/noparse]
The joys of BBCode. :P
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
It's actually code=cplusplus you guys!
You would use the same language names as in our code snippets section.
cscgal
The Queen of DaniWeb
19,424 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
I have my code written very nice on my compiler with proper spacing and good alignment, how do i put it on daniweb so it looks like my compiler. everytime i make a thread and space it right the preview of the post looks messed up....
1) You could readThe Rules as requested when you registered.
2) You could read the post titled "Read This Before Posting" at the top of the forum
3) You could read the words on the background of the box you typed all your messages in.
:icon_rolleyes:
Check out this link on how to do it (I'm linking rather than showing you myself because I myself haven't figured out how to make it display the words "code=C++" and "/code" as text without it getting interpreted as code).
You mean like [code]enter code[/code]? :icon_wink:
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
joeprogrammer and vmanes, thanks for the tutorial:
[code=c++]
// your code here
[/code]
Now I can tell people to use code tags too!:)
WaltP, you get the prize for creativity. I'm gonna have to research why it works, but it does:
[co[B][/B]de]enter code[/co[B][/B]de]
yields
[code]enter code[/code]
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
I think your bracket in line 28 is far too high. It ends the while loop too soon. In fact I think you can delete it completely as you have one in line 62. Do you have an extra one? You want the while loop to end at line 62, right? I think delete that bracket on line 28 and the one on line 66.
After that, I think you do not want to redeclare the boolean variable "done" here:
if (choice == 3)
{
bool done = true;
}
You have declared "done" higher in the program and in a wider scope. The code directly above creates a NEW local variable called "done" which is DIFFERENT from the "done" variable that your while loop tests. The new variable immediately goes out of scope and the above code has no effect on the variable named "done" that you are checking in your while loop. Thus that while loop ends up as an infinite loop. In the above code block, take the "bool" out like this and the "done" that is checked in the while loop will be set to true, which is what I believe you want.
if (choice == 3)
{
done = true;
}
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
I think you actually want the bracket that was on line 66 AFTER the function header rather than before, so don't delete it, just move it?
{ // bracket from line 66
int FahrenheittoCelsius(int)
result = 5*(temperatureF-32)/9;
return result;
}
Should be here instead?
{ // delete this bracket
int FahrenheittoCelsius(int)
{ // put it here instead
result = 5*(temperatureF-32)/9;
return result;
}
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
float CelsiustoFahrenheit(int)
{
//
// This fails because you are dividing using two integers here,
//
// result = ((9/5)*temperatureC)+32;
//
// use the following instead
//
result = ((9/5<strong>.0</strong>)*temperatureC)+32;
return result;
}
You might want to run the following snippet to see the difference
cout
<< "9/5 using integers is [ " << 9/5 << " ]" << endl
<< "9/5 using floating point is [ " << 9/5.0 << " ]" << endl;
mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
Man you have to keep in mind i have been doing this for only two months. I am trying really hard to learn the ropes, so please refrain from giving me crap about writing code and formatting because i do what i think is "correct formatting". I am trying my very best and appreciate all of the help, because this stuff is very overwhelming to me and i am trying hard to understand it.
I'm not giving you crap. You don't have to get defensive. If you are trying to "learn the ropes", doesn't that include learning how to format your code correctly? Especially from a professional programmer? If you are new to programing, how can you expect to have "correct formatting" yet? I'm simply pointing out one way to learn it.
If you format your code properly
1) You will be able to follow it easier
2) We can follow it easier
3) We can give you better and faster responses because the code's easy to read.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944