Thread: Extra input !!!

  1. #1
    Registered User
    Join Date
    Sep 2016
    Posts
    2

    Extra input !!!

    Extra input !!!-result-pngExtra input !!!-code-png

    The program is taking an extra char and doesn't show the result before that .... There r no errors or warnings ... The program is for finding the sum n average of n integers... anyone can help ? .... N ya Turbo C++ is what i used because my college believes its better for learning n others are for working.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You should control the loop with the return value of scanf, e.g.,
    Code:
    while (inc <= loop && scanf("%d", &a) == 1)
    This way, when scanf fails due to an error or end of input, the loop ends.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > N ya Turbo C++ is what i used because my college believes its better for learning n others are for working.
    Ask your tutor how learning something that was made obsolete in 1990 prepares you for working in the outside world.

    By the time you start work, it will no doubt be nearly 2020, and your knowledge will be 30 years out of date.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    > Turbo C++ is what i used because my college believes its better for learning n others are for working.

    Dafuq? A modern compiler and Notepad is a better option than Turbo C++. This is why onboarding a programmer fresh out of college takes so long; we have to undo all of the bad habits school introduced, reteach the language as it is now, and teach the tools that are actually used in the real world.

    On a side note, your loop has an off-by-one error. When you enter 3, it loops four times due to starting at 0 and using <= as the condition.
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Sep 2016
    Posts
    2
    Thank you @Prelude and @laserlight ..... n ya i agree with turbo c++ thing u all said ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 10-29-2014, 04:02 AM
  2. getting two extra ?? while reading my input file
    By monsoonwinds7 in forum C++ Programming
    Replies: 3
    Last Post: 09-23-2011, 03:58 PM
  3. Replies: 2
    Last Post: 07-29-2011, 07:02 AM
  4. One Extra Input
    By swanley007 in forum C++ Programming
    Replies: 6
    Last Post: 11-07-2005, 11:51 AM
  5. Input looping......it appears once extra time!?
    By siumui in forum C Programming
    Replies: 3
    Last Post: 11-15-2002, 10:19 PM

Tags for this Thread