MHB Function errors: Copying one function to create another.

  • Thread starter Thread starter Teh
  • Start date Start date
  • Tags Tags
    Errors Function
Click For 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?
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 6 ·
Replies
6
Views
12K
  • · Replies 2 ·
Replies
2
Views
9K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 39 ·
2
Replies
39
Views
4K
  • · Replies 11 ·
Replies
11
Views
2K
Replies
6
Views
2K
Replies
12
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 23 ·
Replies
23
Views
2K
Replies
3
Views
1K