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
    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( );
    double myDegree;
    char myScale;

Temp Temp :: Fahrenheit( )
{//converting to Fahrenheit
        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

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


Please help me! Thanks :)

Edited by Nick Evan: Fixed formatting

12 Years
Discussion Span
Last Post by gusano79

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

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.