Temperature Converter!!

#include <cmath>

using namespace std;

class TemperatureConverter {

private:

double KelvinTemperature;
double Kelvin;

public:

TemperatureConverter() {

Kelvin = 0;

TemperatureConverter(double x); {
Kelvin = x;
}
}

void setTempFromKelvin(double temp) {
Kelvin = temp;
}

void setTempCelsius(double temp) {

KelvinTemperature = temp + 273.15;
}


double GetTempAsCelsius();

double GetTempFromFahrenheit();

double getKelvin();



void setTempFromFahrenheit(double temp);



};


Temperature::Temperature() {

KelvinTemperature = 0;

}


double GetTempAsCelsius() {

return KelvinTemperature - 273.15;

}

double GetTempAsFahrenheit() {

return (((Kelvin*9)/5 + 32)-273.15);

}

double GetTempFromKelvin() {

return Kelvin;

}

double GetFromCe


void setTempFahrenheit(double temp) {

Kelvin((temp - 32.0 ) */9.0) + 273.15));

}



int main() {

double Celsius;

double Fahrenheit;

double Kelvin;



return 0;

}
This is the error I keep getting. Please help!

Running /home/ubuntu/workspace/lab9/lab99.cpp
/home/ubuntu/workspace/lab9/lab99.cpp: In constructor ‘TemperatureConverter::TemperatureConverter()’:
/home/ubuntu/workspace/lab9/lab99.cpp:18:25: error: expected primary-expression before ‘(’ token
TemperatureConverter(double x); {
^
/home/ubuntu/workspace/lab9/lab99.cpp:18:26: error: expected primary-expression before ‘double’
TemperatureConverter(double x); {
^
/home/ubuntu/workspace/lab9/lab99.cpp:19:18: error: ‘x’ was not declared in this scope
Kelvin = x;
^
/home/ubuntu/workspace/lab9/lab99.cpp: At global scope:
/home/ubuntu/workspace/lab9/lab99.cpp:48:1: error: ‘Temperature’ does not name a type
Temperature::Temperature() {
^
/home/ubuntu/workspace/lab9/lab99.cpp: In function ‘double GetTempAsCelsius()’:
/home/ubuntu/workspace/lab9/lab99.cpp:57:12: error: ‘KelvinTemperature’ was not declared in this scope
return KelvinTemperature - 273.15;
^
/home/ubuntu/workspace/lab9/lab99.cpp: In function ‘double GetTempAsFahrenheit()’:
/home/ubuntu/workspace/lab9/lab99.cpp:63:15: error: ‘Kelvin’ was not declared in this scope
return (((Kelvin*9)/5 + 32)-273.15);
^
/home/ubuntu/workspace/lab9/lab99.cpp: In function ‘double GetTempFromKelvin()’:
/home/ubuntu/workspace/lab9/lab99.cpp:69:12: error: ‘Kelvin’ was not declared in this scope
return Kelvin;
^
/home/ubuntu/workspace/lab9/lab99.cpp: At global scope:
/home/ubuntu/workspace/lab9/lab99.cpp:76:1: error: expected initializer before ‘void’
void setTempFahrenheit(double temp) {
^
Please use code tags. http://www.cplusplus.com/articles/jEywvCM9/
You can edit your post, highlight your code and click the <> button on the right.

1
2
3
TemperatureConverter(double x); {
    Kelvin = x;
}

Semi-colon where it's not expected.

You're missing a semi-colon after the closing curly brace for your TemperatureConverter class.
closed account (48T7M4Gy)
I think you need to review your textbook but here's a start on extensive repair work required:

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
33
34
35
36
37
38
39
40
41
42
#include <iostream>

class TemperatureConverter {
    
private:
    
    double KelvinTemperature;
    double Kelvin;
    
public:
    
    TemperatureConverter()
    {
        Kelvin = 0;
    }
    
    TemperatureConverter(double x)
    {
        Kelvin = x;
    }
    
    void setTempFromKelvin(double);
    double getTempFromKelvin();
};

void TemperatureConverter::setTempFromKelvin(double temp)
{
    Kelvin = temp;
}

double TemperatureConverter::getTempFromKelvin()
{
    return Kelvin;
}

int main() {
    
    TemperatureConverter tc(246.123);
    std::cout << tc.getTempFromKelvin() << '\n';
    
    return 0;
}
Topic archived. No new replies allowed.