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

  • SEARCH
  • Home
  • 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 775449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:17:28+00:00 2026-05-14T19:17:28+00:00

The following code compiles fine, but does not allow the user to choose whether

  • 0

The following code compiles fine, but does not allow the user to choose whether or not the program is to run again. After giving the user the answer, the program automatically terminates. I placed the main code in a “do while” loop to have the ability to convert more than one time if I wanted too. I have tried to run the program in the command line (Mac and Ubuntu machines) and within XCode with the exact same results. Any assistance would be greatly appreciated.

  • C Beginner

P.S. Compiling on MacBookPro running Snow Leopard.


#include <stdio.h>
#include <stdlib.h>

int main(void)
{

        char anotherIteration = 'Y';

        do
        {
                const float Centimeter = 2.54f;
                float inches = 0.0f;
                float result = 0.0f;

                // user prompt
                printf("\nEnter inches: ");
                scanf("%f", &inches);

                if (inches < 0) {
                        printf("\nTry again. Enter a positive number.\n");
                        break;
                } else {
                        // calculate result
                        result = inches * Centimeter;
                }

                printf("%0.2f inches is %0.2f centimeters.\n", inches, result);

                // flush input
                fflush(stdin);

                // user prompt
                printf("\nWould you like to run the program again? (Y/N): ");
                scanf("%c", &anotherIteration);

                if ((anotherIteration != 'Y') || (anotherIteration != 'N'))
                {
                        printf("\nEnter a Y or a N.");
                        break;
                }

        } while(toupper(anotherIteration == 'Y'));

        printf("Program terminated.\n");

        return 0;
}
  • 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-14T19:17:29+00:00Added an answer on May 14, 2026 at 7:17 pm

    You have a few bugs, but since you’re learning, you should probably figure them out. The answer to your specific question on this program is that you probably want to be using fpurge() for stdin, not fflush().

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

Sidebar

Related Questions

The following code does not compile with gcc 4.7 (20120114) , but compiles fine
the following code compiles with Visual Studio 2008 but not with g++ on Mac
The following code compiles fine. but when goes to linking, it shows following error
This code reads and updates the form fine when I run the program, but
I came across the following code that compiles fine (using Visual Studio 2005): SomeObject
The following code compiles in Visual C++ and gcc, but fails with Code Warrior
The following code compiles perfectly with Eclipse, but fails to compile with javac: public
I am unclear about the following. First, this code compiles fine: #include <vector> typedef
The following code compiles fine: template<typename T> void f(const T &item) { return; }
Under MonoTouch the following line of code compiles, but generates an InvalidProgramException: var bytes

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.