User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,488 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,734 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 805 | Replies: 2
Reply
Join Date: Sep 2007
Posts: 1
Reputation: St!tch is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
St!tch St!tch is offline Offline
Newbie Poster

Question Code not adding my numbers correctly...

  #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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2005
Posts: 3,834
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 23
Solved Threads: 436
Colleague
Salem's Avatar
Salem Salem is offline Offline
banned

Re: Code not adding my numbers correctly...

  #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  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,541
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 40
Solved Threads: 972
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Code not adding my numbers correctly...

  #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.
<<Freelance Programmer>> << Hobby Site>>
Signature links for sale. PM me for details
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 3:06 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC