MHB Function errors: Copying one function to create another.

  • Thread starter Thread starter Teh
  • Start date Start date
  • Tags Tags
    Errors Function
AI Thread Summary
The discussion revolves around creating a new function, KelvinToCelsius, based on the existing CelsiusToKelvin function. The user is struggling with the implementation and understanding of how to correctly modify the function. They initially attempted to replicate the CelsiusToKelvin logic but incorrectly calculated the conversion. The key point is that to convert Kelvin to Celsius, the formula should subtract 273.15 from the Kelvin value, not add it. Clarification on the correct formula is crucial for resolving the user's confusion.
Teh
Messages
47
Reaction score
0
I am having difficulties understanding this program may someone help me please.

Using the CelsiusToKelvin function as a guide, create a new function, changing the name to KelvinToCelsius, and modifying the function accordingly.
Code:
#include <iostream>
using namespace std;

double CelsiusToKelvin(double valueCelsius) {
   double valueKelvin = 0.0;

   valueKelvin = valueCelsius + 273.15;

   return valueKelvin;
}

/* Your solution goes here  */

/* ^ Your solution goes here ^ */

int main() {
   double valueC = 0.0;
   double valueK = 0.0;

   valueC = 10.0;
   cout << valueC << " C is " << CelsiusToKelvin(valueC) << " K" << endl;

   valueK = 283.15;
   cout << valueK << "  is " << KelvinToCelsius(valueK) << " C" << endl;

   return 0;
}
output: main.cpp: In function ‘int main()’:
main.cpp:24:55: error: ‘KelvinToCelsius’ was not declared in this scope
 
Technology news on Phys.org
Where are you having difficulty? Do you know you need to declare a function

[m]double KelvinToCelsius(double valueKelvin) {. . .}[/m]​

?
 
greg1313 said:
Where are you having difficulty? Do you know you need to declare a function

[m]double KelvinToCelsius(double valueKelvin) {. . .}[/m]​

?
The issue I have was to understand how this works
if i was to change the function to KelvinToCelsius
Code:
double CelsiusToKelvin(double valueCelsius) {
   double valueKelvin = 0.0;

   valueKelvin = valueCelsius + 273.15;

   return valueKelvin;
}

- - - Updated - - -

Teh said:
The issue I have was to understand how this works
if i was to change the function to KelvinToCelsius
Code:
double CelsiusToKelvin(double valueCelsius) {
   double valueKelvin = 0.0;

   valueKelvin = valueCelsius + 273.15;

   return valueKelvin;
}

This what I got so far and thanks for the help

Code:
double KelvinToCelsius (double valueKelvin) {
   double valueCelsius = 0.0;
   
   valueCelsius = valueCelsius + 273.15;
   
   return valueCelsius;

}
output:

Testing with valueKelvin = 283.15
Expected value: 10
Your value: 273.15
 
If you solve [m]valueKelvin = valueCelsius + 273.15[/m] for [m]valueCelsius[/m], what do you get?
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top