Repeated addition

This is a discussion on Repeated addition within the C++ Programming forums, part of the General Programming Boards category; As mentioned before, if you move the print statement to after the loop, after the calculation is complete, then it ...

  1. #16
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    As mentioned before, if you move the print statement to after the loop, after the calculation is complete, then it should work as expected.

  2. #17
    Registered User BB89's Avatar
    Join Date
    Sep 2009
    Location
    Dallas, Texas
    Posts
    72
    Ok, I got it now.

    Thanks to everyone that helped me.

  3. #18
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    Quote Originally Posted by stumon View Post
    Get your cout statement out of the while loop. Put it right after it ends if you want just the final answer printed.
    Don't hand out solutions, please. The OP should be able to realize this logic error by him/herself.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    195
    well, in the source code you quoted in your other post the condition on the while statement is 'B>0'. If B = 0, then this condition is never met and anything inside the while loop never gets executed. Thats why you don't get anything happening.

  5. #20
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    Quote Originally Posted by Elysia View Post
    Don't hand out solutions, please. The OP should be able to realize this logic error by him/herself.
    Obviously the OP didn't realize it or else (s)he wouldn't have asked why it prints out each addition. I gave a simple solution to a simple question after (s)he had already presented some working code. If that is frowned upon then whats the point to this forum?
    The keyboard is the standard device used to cause computer errors!

  6. #21
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    If the OP cannot do logic on his/her own, then he/she should quit being a programmer. It's that simple.
    A programmer--any programmer--MUST be able to structure the code properly.
    What we can help with is other types of problems. For example, how does cin work? How do classes work? Why do I get a segmentation fault, etc.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #22
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    Hahaha. Funny when I see some people ask those questions, they get "check the FAQ", or "Google it".... I feel answering a simple question about something that the OP may understand but overlooked is one of the many reasons for this forum. Now this is getting off topic so i'm done. It's okay though. You keep doing your thing, I will keep doing my. Its all about help and advice.
    The keyboard is the standard device used to cause computer errors!

  8. #23
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    They point to these things because usually something is answered in the FAQ, and we are too lazy to type it out or the FAQ explains it way better. Sometimes a simple search in google yields thousands of links to resources that explains the question, so why not just tell them to google it? Faster for us, and probably even better for them.
    If it isn't about a logic question--ie how to structure the code in a certain way, then feel free to provide an answer. But try not to completely solve the problem. After all, they learn by doing. If you guide them along the path, they will learn all the better.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Repeated Addition
    By rocksteady in forum C Programming
    Replies: 15
    Last Post: 12-11-2007, 06:05 AM
  2. PC Issue: Repeated Long Beeps
    By alphaoide in forum Tech Board
    Replies: 8
    Last Post: 07-19-2005, 08:46 AM
  3. need some help with binary addition.
    By InvariantLoop in forum C++ Programming
    Replies: 21
    Last Post: 01-27-2005, 05:52 AM
  4. Check for repeated digits!
    By CrackerJack in forum C Programming
    Replies: 5
    Last Post: 11-08-2003, 10:37 PM
  5. Problems with an addition operator
    By jamjar in forum C++ Programming
    Replies: 12
    Last Post: 03-28-2003, 12:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21