Thread: Small Problem with double and integer adding?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    114

    Small Problem with double and integer adding?

    The Problem here is that when i write a double variable then a int variable i get no out put and are stuck waiting

    Code:
    #include<iostream>
    #include<windows.h>
    #include<conio.h>
    using namespace std;
    double input(double, double);
    int input(int, int);
    double input(double, int);
    //OVERLOADING ADDITION//
    int main()
    {
       cout.setf(ios::showpoint);
       cout.setf(ios::showpos);
       cout.setf(ios::fixed);
       cout.precision(2);
       int x = 0;
       int y = 0;
       int n = 0;
       int run = 1;
      
      double dnumber;
      int inumber;
      
      double dnumber2;
      int inumber2;
      char c;
      double danswer =0;
      int ianswer =0;
    while(run == 1)
    {
     while(n < 2)
     {
        cout <<"Do you want the number to be decimal placed or whole number <D> <W>?:";
       for(;;)
       {
          if(n == 2)
          {
            system("cls");
            break;
          }
       c=toupper(getch());
       
       if(c == 'D')
       {
           if(x == 1)
           {
                system("cls");
                cout <<"Input a number:";
                cin >> dnumber2;
                n = 2;
                x = 2;
                c = ' ';        
           }
           if(x == 0)
           {
                system("cls");
                cout <<"Input a number:";
                cin >> dnumber;
                n = n++;
                x = 1;
                c = ' ';
                system("cls");
                if(y == 0)
                {
                      cout <<"Do you want the number to be decimal placed or whole number <D> <W>?:";
                }
           }
       }
       else if(c == 'W')
       {
           if(y == 1)
           {
                system("cls");
                cout <<"Input a number:";
                cin >> inumber2;
                n = 2;
                y = 2;
                c = ' ';
                
           }
           if(y == 0)
           {
                system("cls");
                cout <<"Input a number:";
                 cin >> inumber;
                 n = n++;
                 y = 1;
                 c = ' ';
                 system("cls");
                 if(x == 0)
                {
                      cout <<"Do you want the number to be decimal placed or whole number <D> <W>?:";
                }
                 
           }
       }
       }//for loop
     } // While n < 2
      if(x == 1 && y == 1)
      {
         danswer = input(dnumber,inumber);
         cout << danswer << endl;
         system("PAUSE");
         x = 0; n = 0; y = 0; dnumber = 0; inumber = 0; ianswer = 0; inumber2 = 0; dnumber2 = 0; danswer = 0; c = ' ';  
      }
      else if(x == 0 && y ==2)
      {
         ianswer = input(inumber,inumber2);
         cout << ianswer << endl;
         system("PAUSE");
         x = 0; n = 0; y = 0; dnumber = 0; inumber = 0; ianswer = 0; inumber2 = 0; dnumber2 = 0; danswer = 0; c = ' ';  
      }
      else if( x == 2 && y == 0)
      {
         danswer = input(dnumber,dnumber2);
         cout << danswer << endl;
         system("PAUSE");
         x = 0; n = 0; y = 0; dnumber = 0; inumber = 0; ianswer = 0; inumber2 = 0; dnumber2 = 0; danswer = 0;  c = ' ';  
      }
      system("cls");
      cout << "Do you wish to run this program again? <N> <Y>:";
    for(;;)
    {
      c = toupper(getch());
      if(c == 'N')
      {
           run = 0;
           break;
      }
      else if(c == 'Y')
      { 
           run = 1;
           break;
      }
    }
      system("cls");       
    } // While Run
    return 0;       
    } // End main
    
    double input(double num1, double num2)
    {
        double num3 = num1 + num2;
        return(num3);
    }
    double input(double num1, int num2)
    {
        double num4 = (double) num2; //Even with out type casting same problem
        double num3 = num4 + num1;
        return(num3);
    }
    int input(int num1, int num2)
    {
        return(num1 + num2);
    }
    Last edited by Nathan the noob; 03-27-2009 at 05:34 PM.
    Who needs a signature?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  2. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 10:53 AM
  3. functions and passing data
    By redmondtab in forum C Programming
    Replies: 41
    Last Post: 09-21-2006, 12:04 PM
  4. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM