Problems regarding passed on value and passed on reference

Hello guys, I'm asking for you assistance of my code. My program aims to display user entered temperature in Kelvin into Celsius and Fahrenheit. So far, my prof explained about passed on value and passed on reference and I need to use them in this assignment. Below are the code of my program so far. The errors are shown after the code.

In Assignment8_function.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<stdio.h>
#include<iostream>
using namespace std;

// Write your tempconvertor function definition here
double tempconverter(double kel)
{
    
   double *celsius = 0.0;
   double fahrenheit = 0.0;
  
  
   if(kel < 0)
   {
       	celsius = -1000.0;
       	fahrenheit = -1000.0;
       	return fahrenheit;
   }
    
   else
   {
       	//celsius = kel – 273.15;
       	celsius = kel - 273.15;
       
	//fahrenheit = (kel X (9/5))–459.67;
	fahrenheit = (kel*(9/5)) - 459.67;
       
	return fahrenheit;

   }
  
}


In Assignment8_main.cpp,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  // In this file, write your main function to test your tempconvertor function
#include "Assignment8_function.cpp"
#include<stdio.h>
#include<iostream>
using namespace std;

// Write the prototype for your tempconvertor function here (above the main function)
double tempconverter(double kel);

int main()
{
   //declaration
   double kelvin;
    
   cout << "enter temperature in kelvin"<<endl;  
   cin >> kelvin;
    
   double temperature = tempconverter(kelvin);
   cout << "the kelvin temperature in fahrenheit" << temperature;

}


But when I try to build the program, the errors below are displayed.
Assignment8_function.cpp: In function ‘double tempconverter(double)’:
Assignment8_function.cpp:9:22: error: cannot convert ‘double’ to ‘double*’ in initialization
double *celsius = 0.0;
^
Assignment8_function.cpp:15:16: error: cannot convert ‘double’ to ‘double*’ in assignment
celsius = -1000.0;
^
Assignment8_function.cpp:23:17: error: cannot convert ‘double’ to ‘double*’ in assignment
celsius = kel - 273.15;
^
In file included from Assignment8_main.cpp:2:0:
Assignment8_function.cpp: In function ‘double tempconverter(double)’:
Assignment8_function.cpp:9:22: error: cannot convert ‘double’ to ‘double*’ in initialization
double *celsius = 0.0;
^
Assignment8_function.cpp:15:16: error: cannot convert ‘double’ to ‘double*’ in assignment
celsius = -1000.0;
^
Assignment8_function.cpp:23:17: error: cannot convert ‘double’ to ‘double*’ in assignment
celsius = kel - 273.15;

Can you guys point up for me where did I go wrong? I can't seem to understand these errors even after make several changes but the errors are still the same.
Last edited on
Where are your references? Read: http://www.cplusplus.com/doc/tutorial/functions/


You have a pointer named 'celsius' that you misuse.
Topic archived. No new replies allowed.