Git Product home page Git Product logo

cs50-greedy.c's Introduction

cs50-greedy.c

CS50 pset1 greddy.c exercise

This code is throwing up some issues with check50. The while loop that calculates the one cent coins required only executes intermittently. I see no problem with the code myself so would appreciate some feedback to identify the issue here.

##Code is below, includes are cs50.h and stdio.h:

include <cs50.h> include <stdio.h>

float change; int count = 0;

int main(void) {

// User input of change owed with negative value repeat prompt
do {
printf("How much change is owed?\n");
change = get_float();
} while (change < 0);

// find minimum number of coins to provide the correct change
while (change >= 0.25) // Quarters
{
    change -= 0.25;
    count++;
}

while (change >= 0.10) // 10 cent coins
{
    change -= 0.1;
    count++;
}

while (change >= 0.05) // 5 cent coins
{
    change -= 0.05;
    count++;
}

while (change >= 0.01) // 1 cent coins  // This is the loop causing the issue with check50
{
    change-= 0.01;
    count++;
}
printf("%i\n", count);

}

check50 results

~/workspace/pset1/ $ check50 2016.greedy greedy.c

:) greedy.c exists

:) greedy.c compiles

:( input of 0.41 yields output of 4 \ expected output, but not "3\n"

:( input of 0.01 yields output of 1 \ expected output, but not "0\n"

:) input of 0.15 yields output of 2

:) input of 1.6 yields output of 7

:) input of 23 yields output of 92

:( input of 4.2 yields output of 18 \ expected output, but not "22\n"

:) rejects a negative input like -.1

:) rejects a non-numeric input of "foo"

:) rejects a non-numeric input of ""

https://sandbox.cs50.net/checks/8eee09fd7628430499c4e99bb63e61bc

cs50-greedy.c's People

Watchers

James Cloos avatar Seamus Connolly avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.