Function errors: Copying one function to create another.

  • Context: MHB 
  • Thread starter Thread starter Teh
  • Start date Start date
  • Tags Tags
    Errors Function
Click For Summary

Discussion Overview

The discussion revolves around the creation of a function named KelvinToCelsius based on an existing function, CelsiusToKelvin. Participants are addressing issues related to function declaration, implementation, and debugging in C++ programming.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant expresses difficulty in understanding how to modify the CelsiusToKelvin function to create the KelvinToCelsius function.
  • Another participant suggests that the user needs to declare the KelvinToCelsius function properly, indicating the required syntax.
  • A later reply indicates confusion about the implementation, showing an incorrect attempt at the KelvinToCelsius function that does not correctly convert Kelvin to Celsius.
  • One participant prompts the original poster to solve for valueCelsius from the CelsiusToKelvin equation, implying a need for understanding the mathematical relationship between Celsius and Kelvin.

Areas of Agreement / Disagreement

Participants do not appear to reach a consensus on the correct implementation of the KelvinToCelsius function, and there is ongoing confusion regarding the conversion logic.

Contextual Notes

The discussion highlights potential misunderstandings in function declaration and the mathematical relationship between Celsius and Kelvin, which may not be fully resolved in the current posts.

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 - - -

the 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?
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
12K
  • · Replies 2 ·
Replies
2
Views
9K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
12
Views
3K
  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
6
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K