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?
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top