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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:00:48+00:00 2026-06-09T03:00:48+00:00

So I’ve been working on the Harvard CS50 course on iTunes U and have

  • 0

So I’ve been working on the Harvard CS50 course on iTunes U and have run into a bit of a problem. The code runs and then stops. I explain the issue where the code is giving me trouble.

// Program calculates the amount of change you can give with the least amount of coins.

 #include <stdio.h>
 #include <cs50.h>
 #include <math.h>

int
main(void)
{

    float change = 0, inputflag = 1;
    int changeint = 0;
    int quarter = 25, dime = 10, nickel = 5, penny = 1; // Coins and values
    int qc = 0, dc = 0, nc = 0, pc = 0; // Coin value change (Qc = Quarter Change)

// Prompts user for input and validates. 

    while (inputflag == 1)
     {
        printf("How much change? ");
        change = GetFloat();

        if (change == 0)
        {
            printf("You have no change!\n");
            inputflag = 0;
        }
        else if (change > 0)
        {
            printf("%.2f\n", change);
            inputflag = 0;
        }
        else
        {
            printf("Please enter a non-negative number! \n");
        }
     } 

The program stops here. I run the code, input an acceptable value and then the program stops running. It doesn’t move onto the part below.

I have spent the last hour going over this and still can’t figure out what is keeping the program from running. The inputflag value gets set to 0 thus breaking the first while loop and then should move on below if (change != 0) which it doesn’t…So any advice would be greatly appreciated.

    if (change != 0) // If the change is zero, this section is skipped
        {
            changeint = round(100 * change);
            printf("%d", changeint);
        }

      // The following four sections subtract coin amount, compare it, and add 1 to count.  
          while (changeint >= quarter);    
          {   
               changeint = changeint - quarter;
               qc = qc + 1;
          }

          while (changeint >= dime);
          {
               changeint = changeint - dime;
               dc = dc + 1;
          }

          while (changeint >= nickel);
          {
               changeint = changeint - nickel;
               nc = nc + 1;
          }

          while (changeint >= penny);
          {
               changeint = changeint - penny;
               pc = pc + 1;
          }

//Prints output

          printf("You owe a total of %d coins!", qc + dc + nc + pc);

}
  • 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-09T03:00:49+00:00Added an answer on June 9, 2026 at 3:00 am

    The semi-colons at the first line of each while statement are to blame. You should remove them to avoid an inevitable infinite loop:

          while (changeint >= quarter) 
          {   
               changeint = changeint - quarter;
               qc = qc + 1;
          }
    
          while (changeint >= dime)
          {
               changeint = changeint - dime;
               dc = dc + 1;
          }
    
          while (changeint >= nickel)
          {
               changeint = changeint - nickel;
               nc = nc + 1;
          }
    
          while (changeint >= penny)
          {
               changeint = changeint - penny;
               pc = pc + 1;
          }
    

    Yes, even the simplest of problems might go undetected, and for/while statements with semi-colons are one of them (which could be intended).

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

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am currently running into a problem where an element is coming back from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.