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 392,093 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 3,884 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:
Views: 639 | 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 2:32 am. Reason: add code tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2005
Posts: 3,267
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 
Rep Power: 20
Solved Threads: 368
Colleague
Salem's Avatar
Salem Salem is offline Offline
void main'ers are DOOMed

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?".
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,562
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 
Rep Power: 36
Solved Threads: 860
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.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Reply

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

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

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