I'm somewhat of a beginner also. what i meant though is not what is inside the parentheses.
for example:
Code:
void Thermometer::setThermometer(double temp)
{
temp = FarenTemp;
}
you cannot do this, it should be changed to:
Code:
void Thermometer::setThermometer(double temp)
{
FarenTemp = temp;
}
in a class, constructors and set modifier functions are supposed to set private data to something.
also, you cannot do things such as:
Code:
void Thermometer::getFarenheit(double t)
{
cout<<"Enter a temperature in degrees Farenheit: ";
cin>>t;
}
you have to do things such as
Code:
std::cin >> FarenTemp;
when you cin to t, this doesn't do anything.
here, try this:
Code:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
class Thermometer
{
public:
Thermometer(); //constructor
//void setThermometer(double); //function to set temp
void getFarenheit(); //function to get temp in F
void getCelcius(); //function to get temp in C
private:
double FarenTemp; //data members in F
};
//Temperature constructor to initialize the data members to zero
Thermometer::Thermometer() {FarenTemp = 0;}
//Function to set temperature using Farenheit.
/*void Thermometer::setThermometer(double temp)
{
FarenTemp = temp;
}*/
//Function to get temperature in degrees F from the user
void Thermometer::getFarenheit()
{
cout<<"Enter a temperature in degrees Farenheit: ";
cin>>FarenTemp;
}
//Funtion to get temperature in degrees C from the user
void Thermometer::getCelcius()
{
cout<<"The temperature in Celcius: "<<(((FarenTemp - 32 ) * 5 ) / 9 );
}
int main()
{
Thermometer x; //instantiates object x of class Thermometer
x.getFarenheit();
x.getCelcius();
cout<<endl;
return 0;
}
This runs and works, at least with 32F to 0C and 212F to 100C.
edit: your formula in getCelcius works, it does not need to be changed. what was making it produce weird answers was the cin >> t line, this doesn't do anything, and once the function is over, it goes away. If you cin >> FarenTemp, it will store this in private data, and when you use that private data, it has what the temp was. Otherwise, FarenTemp contains garbage.
also, when you assign FarenTemp, you should assign FarenTemp the value of the parameter, and not assign the parameter the value of FarenTemp. That function wasn't needed, so I commented it out. But if it is a homework, and you are supposed to have the function, you have to think through your code more.
If I offended you with my previous post, it was not intended and I am sorry for that. I am here to help people learn, and to learn myself.
I hope this helps some, if you have any more questions, post up.