Thread: Problem Calling Destructor, and prob with cin.

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    28

    Problem with cin. I want the characters after input to stay on the same line.

    EDIT::: i fixed the problem with the contructor

    However, cin automaticly moves to the next line after input. Is there a way i can make Cin stay on the same line, so i can use the +, -, *, and / characters after it? Compile the code and you'll see what i mean.

    CODE:

    Code:
    #include <iostream>
    #include <stdlib.h>
    
    class calc
    {
     private:
        long double *num;
          
     public:
          calc();
          ~calc();
          void getnum();
          
          long double  numreturn(){ return *num;} //returns number to print on screen//
    };
    
    
    calc::calc()
    {
     num = new long double;
    }
    
    calc::~calc()
    {
     delete num;
    }
    
    void calc::getnum()
    {
     calc();
     cin>> *num;
    }
    
    
    int main(int argc, char *argv[])
    { 
     int choose = 0, loop = 0;                     
     calc num1, num2;//Instances hold the 2 numbers used in them math//                               
     cout<<"Type the number of what you want to do, then press [ENTER]\n\n";
     cout<<"1..........Addition\n"                 //The menu//
           "2..........Subtraction\n"
           "3..........Multiplication\n"
           "4..........Division\n\n"
           "5..........End Program\n\n\n";
           
     
                         do{
     cout<<"What do you want to do? ";
     cin>>choose;
     switch(choose)                     
     {
      case 1:
       {
        cout<<"Addition\n";
        num1.getnum(); cout<<" + ";  num2.getnum(); cout<<" = "<<num1.numreturn() + num2.numreturn();
        break;
       }
      case 2:
       {
        cout<<"Subtraction\n";
        num1.getnum(); cout<<" - ";  num2.getnum(); cout<<" = "<<num1.numreturn() - num2.numreturn();
        break;
       }
      case 3:
       {
        cout<<"Multiplication\n";
        num1.getnum(); cout<<" * ";  num2.getnum(); cout<<" = "<<num1.numreturn() * num2.numreturn();
        break;     
       }
      case 4:
       { 
        cout<<"Division\n";
        num1.getnum(); cout<<" / ";  num2.getnum(); cout<<" = "<<num1.numreturn() / num2.numreturn();
        break;
       }
      case 5:
       {
        cout<<"Program Closing\n\n\n\n";
        loop = 1;
        num1.~calc(); num2.~calc();
        break;
       }
      default:
       {
        cout<<"Not a choice, program returning to Menu\n\n";
        break;
       }
     }
                            }
     while(loop == 0);
      
      system("PAUSE");	
      return 0;
    }
    Last edited by imortal; 10-10-2003 at 09:30 AM.
    ~matt~

  2. #2
    Registered User
    Join Date
    Dec 2002
    Posts
    28

    ...continued

    EDIT:: Fixed problem with contstructor.
    Last edited by imortal; 10-10-2003 at 09:25 AM.
    ~matt~

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    28
    I know this is alot of code for a Command line calculator but its i only made it to help me understand pointers and classes better.
    ~matt~

Popular pages Recent additions subscribe to a feed