Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6657379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:45:39+00:00 2026-05-26T01:45:39+00:00

The program is ignoring Stop when amt is 0 until after 10 numbers have

  • 0

The program is ignoring Stop when amt is 0 until after 10 numbers have been entered. The program also doesn’t stop after 10 numbers have been entered. Where is my error?

main() {
int amt;
int tot = 0; /* running total */
int i = 0;   /* counts number of times in loop */
while (amt!=0 || i < 10)
    {
     printf("Enter a number (enter 0 to stop): ");
     scanf("%d", &amt);
     tot = tot + amt;
     i++;
    }
printf("The sum of those %d number is %d.\n", i, tot);

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:45:40+00:00Added an answer on May 26, 2026 at 1:45 am

    Your test is happening before amt is assigned. Thus its results are undefined. This test should be moved to the end of the iteration, i.e. a do/while. Whilst you could assign amt to some non-zero value this feels slightly untidy to me.

    And surely you mean to use logical AND rather than logical OR? You only want to continue iterating if both amt is non-zero AND i<10.

    Of course, if you did move the test to the end of the iteration then you would have to account for the fact that i had been incremented inside the loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Most program languages have some kind of exception handling; some languages have return codes,
My Program overrides public void paint(Graphics g, int x, int y); in order to
Strange program hang, what does this mean in debug? After attaching windbg I found
I am trying to improve SQLite error handling in an existing C++ program. I
Memory allocation in a program: Code and data. Stack. Heap. If I have a
Firefox seems to be ignoring some JavaScript code in my program. The code below
Question: I have written a console program that uses the SQL server 2005 web
I have a program that runs in the Win32 environment. There is one variable
Recently, I have a try to build and run sample hello world program of
I have a C++ code base that has been working for a long time.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.