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 8906631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:42:22+00:00 2026-06-15T02:42:22+00:00

I have written this program which changes the entered height (in cm) to feet

  • 0

I have written this program which changes the entered height (in cm) to feet and inches. When I run it, the result keeps coming up without stopping. Does anyone know why?

#include <stdio.h>

int main (void)
{
  float heightcm;
  float feet;
  float inch;

  printf("Enter height in centimeters to convert \n");
  scanf("%f", &heightcm);

  while (heightcm > 0)
  {
   feet = heightcm*0.033;
   inch = heightcm*0.394;

   printf("\n %0.1f cm = %0.2f feet and %0.2f inches \n", heightcm,feet,inch);
  }
 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-06-15T02:42:24+00:00Added an answer on June 15, 2026 at 2:42 am

    You made an infinite loop:

      while (heightcm > 0)   // if user enters a height > 0 we get in
      {
       feet = heightcm*0.033; // update feet 
       inch = heightcm*0.394; // update inches
    
       // print the result
       printf("\n %0.1f cm = %0.2f feet and %0.2f inches \n", heightcm,feet,inch); 
      }
    

    No where in the loop is heightcm changed, which means that it’s always > 0 and your function will loop forever and never terminate. A if check makes more sense here:

      if (heightcm > 0)   // if user enters a height > 0 we get in
      {
       feet = heightcm*0.033; // update feet 
       ...
    

    Or you can use your while loop and keep asking for more input:

      while (heightcm > 0)
      {
        printf("Enter height in centimeters to convert \n");
        scanf("%f", &heightcm);
        ...
    

    Which is probably what you were going for (loop until the user enters a non-positive number)

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

Sidebar

Related Questions

I have written this program, which sorts some ints using a functor: #include<iostream> #include<list>
I have written php program and uploaded on server. I want run this program
I have written a program which will serialize and de-serialize, it does this fine
Assume that i have written a program in C++ without using RTTI and run-time
I have written a program that uses qhttp to get a webpage. This works
I have written the following C program. The output is 32. Why is this?
This is the situation : I mostly program C# and have written types in
I have this servlet program and an external .jar file (written by someone else)
have written this little class, which generates a UUID every time an object of
I have written a mail-processing program, which basically slaps a template on incoming mail

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.