Code not adding my numbers correctly...

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 1
Reputation: St!tch is an unknown quantity at this point 
Solved Threads: 0
St!tch St!tch is offline Offline
Newbie Poster

Code not adding my numbers correctly...

 
0
  #1
Sep 11th, 2007
This is my code below:
  1. using namespace std;
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5. int thisisanumber;
  6. int SecondNumber;
  7. int TotalNumber;
  8. TotalNumber = thisisanumber + SecondNumber;
  9.  
  10. cout<<"Please enter a number: ";
  11. cin>> thisisanumber;
  12. cin.ignore();
  13. cout<<"You entered: "<< thisisanumber <<"\n";
  14. cin.get();
  15.  
  16. cout<<"Please enter a second number: ";
  17. cin>> SecondNumber;
  18. cin.ignore();
  19. cout<<"Your second number is: "<< SecondNumber <<"\n";
  20. cin.get();
  21.  
  22. cout<<"Your Total is: "<< TotalNumber <<"\n";
  23. cin.get();
  24.  
  25. cout<<"Thank you for your patience with my new small but mighty program!";
  26. cin.ignore();
  27.  
  28.  
  29. }
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.
Last edited by Ancient Dragon; Sep 12th, 2007 at 3:32 am. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Code not adding my numbers correctly...

 
0
  #2
Sep 12th, 2007
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?".
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,634
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1497
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Code not adding my numbers correctly...

 
0
  #3
Sep 12th, 2007
Originally Posted by St!tch View Post
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC