Member Avatar for St!tch

This is my code below:

using namespace std;

int main(int argc, char *argv[])
{
    int thisisanumber;
    int SecondNumber;
    int TotalNumber;
    TotalNumber = thisisanumber + SecondNumber;
     
  cout<<"Please enter a number: ";
  cin>> thisisanumber;
  cin.ignore();
  cout<<"You entered: "<< thisisanumber <<"\n";
  cin.get();
  
  cout<<"Please enter a second number: ";
  cin>> SecondNumber;
  cin.ignore();
  cout<<"Your second number is: "<< SecondNumber <<"\n";
  cin.get();
  
  cout<<"Your Total is: "<< TotalNumber <<"\n";
  cin.get();
  
  cout<<"Thank you for your patience with my new small but mighty program!";
  cin.ignore(); 
  
  
}

I'm starting out...obviously, a newbie here. However, I cannot understand that when I run this code with the first number being 34 and my second number being 40 ....I get the output of 39.

This is not my homework. I'm just trying to learn on my own for now.

Thanks for all you help.

Sincerely,
St!tch.

And I can't understand how 99% of new posters can fail to read the intro threads properly (or at all).
http://www.daniweb.com/forums/announcement8-3.html

Or completely ignore the watermark at the back of the edit window.

Or fail to press "preview" to make sure their post is going to come out right.

Or fail to read other peoples posts and wonder, "hey, I wonder how they got the code all nice?".

I'm starting out...obviously, a newbie here. However, I cannot understand that when I run this code with the first number being 34 and my second number being 40 ....I get the output of 39.

This is not my homework. I'm just trying to learn on my own for now.

Thanks for all you help.

Sincerely,
St!tch.

Move line 8 down to line 21. Code is executed in the order that it appears in the program, which means the two numbers can not be added together until after their values are known.

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.