Hi!
Thanks for the help regarding vectors :) It really helped me.

Now, I have a problem regarding classes. I do not know the problem in this program

#include <iostream.h>
#include <ctype.h>   //islower(), toupper()
#include <stdlib.h>      //exit( )
class Temp
{
   public:
    Temp( );
    Temp(double initDeg, char initScale);
    double Degrees();
    char Scale();
Temp Fahrenheit( );
Temp Celsius( );    //needed to work on
Temp Kelvin( ); //needed to work on
void Read( );
    void Print( );
   private:
    double myDegree;
    char myScale;
};


Temp Temp :: Fahrenheit( )
{//converting to Fahrenheit
    switch(myScale)
    {
        case ‘F’:   return Temp(myDegrees, ‘F’);
        case ‘C’:   return Temp(myDegrees*1.8+32.0, ‘F’);
        case ‘K’:   return Temp(myDegrees-273.15, ‘F’);
    }
}

void main()
{
      cout<<"This program shows the Fahrenheit, Celcius,"
       <<" and Kelvin equivalents of a temperature.\n\n";

   char response;
   Temp theTemp;  //construction

   do
   {    cout<<"Enter a temperature(e.g., 98.6 F): ";
    cin>>theTemp;   //input
    cout<<"-->"
        <<theTemp.Fahrenheit()
        <<" = "
        <<theTemp.Celcius()
        <<" = "
        <<theTemp.Kelvin()
        <<endl;
    cout<<"\nDo you want to have more temperature conversion?";
    cin>>response;
   }while(response=='Y' || response=='y');

}

Please help me! Thanks :)

Recommended Answers

All 2 Replies

Can you give us a hint as to where to look, what you are seeing, how you know it doesn't work? Does it compile? Run? Give unexpected results?

We might be able to help if we know what we're looking for.

Well, here's an easy one--you've spelled a method two different ways (the first is correct):

...
Temp Celsius( ); //needed to work on
...
<<theTemp.Celcius()
...

Also, it won't compile until you actually define a body for that method like you did for Temp::Fahrenheit.

Hm, also noticed you have both myDegree and myDegrees in your code; I bet you don't want that either.

Unless you've snipped out lots of code, it looks like you haven't actually implemented half of the class members... including the constructor that actually accepts an argument and (one would imagine) initializes myDegree. Without that, it'll always be zero.

And... this looks suspicious:

...
cin>>theTemp; //input
...

There's no way for the compiler to know that you want a double-precision value to be read... you need a double somewhere to hold the value.

That should get you started.
--sg

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.