- #1
elly_55
Poster has been reminded to use the Homework Help Template when starting threads in the schoolwork forums
Hi everybody,
I seem to be having trouble coding a function that returns the integer value at which degrees celsius is equivalent to degrees fahrenheit. Here is the question:
Write a function that will find a temperature that is the same in both Fahrenheit and Celsius. First define two variables farTemp and celTemp and initialize celTemp to 100. Using a loop decrement (or decrease) the celTemp by 1 and check if the calculated farTemp is equal to the celTemp. Stop the loop when farTemp=celTemp
Here is the code that I have so far,
Specifically I seem to be having problems understanding how to code the boolean statement within my for loop, but if you see any problems or simplifications that can be made please share as I am brand new to coding and would love to learn from anyone more experienced!
I seem to be having trouble coding a function that returns the integer value at which degrees celsius is equivalent to degrees fahrenheit. Here is the question:
Write a function that will find a temperature that is the same in both Fahrenheit and Celsius. First define two variables farTemp and celTemp and initialize celTemp to 100. Using a loop decrement (or decrease) the celTemp by 1 and check if the calculated farTemp is equal to the celTemp. Stop the loop when farTemp=celTemp
Here is the code that I have so far,
C:
int cent, fahr;
cout << "input your temperature in degrees celsius \n";
cin >> cent;
CentEqualF (int cent)
{
for (cent = 100; cent == -273; cent --) // is the parameter here a valid statement (cent == -273)?
fahr = ( (cent*1.8) +32 )
if fahr % cent == 1
cout << cent << "is the temperature at which both measurement systems are equivalent \n";
else
[I]
// this is where I get really stuck I know that if my 'if' statement is true then i want the computer
// to output the temperature. And if the above 'if' statement is false I would like the loop
// to iterate until the 'if' statement is true but I do not know what to do in order to fix this.
// I have found several other websites where people ask essentially the same question
// but I find myself doing more copying than understanding. Thanks for the help![/I]
}
Last edited by a moderator: