Problem with adding numbers


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Problem with adding numbers

  1. #1
    Join Date
    Dec 2005
    Posts
    5

    Problem with adding numbers

    Hey, I'm trying to write a very simple program to add up numbers, but after I enter the second number the program finishes. Here is the code:

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        int num1, num2, total;
        
        cout <<"Enter the first number: ";
        cin >> num1;
        cout <<"Enter the second number :";
        cin >> num2;
        total = num1 + num2;
        cout <<"The total is :" << total << endl;
        cin.get();
        return 0;
    }
    it seems to ignore the cin.get function. Can anyone help please? I'm using Dev-C++ 5 beta. Thanks in advance.

    -Pinny.

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    we've had several posts about this very issue recently. You can scroll down the thread list and find a more detailed answer, but the bottom line is that you need to add a certain input statement that causes the program to wait until the user presses a key. Something like
    char c;
    cin>>c; before the last line in main() would do the trick.
    Danny Kalev

  3. #3
    Join Date
    Jan 2006
    Posts
    55
    Try this
    cin.ignore(10000,'\n');
    cin.get();

Similar Threads

  1. How can I solve this problem?
    By ignite in forum Java
    Replies: 8
    Last Post: 02-27-2005, 08:59 AM
  2. Reliability Problem
    By elise in forum Java
    Replies: 0
    Last Post: 10-30-2002, 04:40 AM
  3. COM+ Problem Pls Help
    By Kevin Moore in forum .NET
    Replies: 3
    Last Post: 06-04-2002, 06:44 PM
  4. problem in adding Data Connection
    By Thomas in forum ASP.NET
    Replies: 1
    Last Post: 03-11-2002, 03:19 PM
  5. Replies: 1
    Last Post: 05-08-2000, 04:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center