0

This is my code for cash idk what I did wrong cuz when I compile it, it gives me a decimal of the number I put in instead of a whole number representing how many coins. Idk what I did wrong.

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

int main(void)
{
    float c;
    do 
    {
        c=get_float("How muh is owed?");
    } while (c < 0);
    
    int cents= round(c * 100);
    int coins = 0;
    
    while (cents >= 25)
        {   cents = cents - 25;
            coins++;    
        }
        while (cents >= 10)
        {
            cents = cents - 10;
            coins++;
        }
        while (cents >= 5)
        {
            cents = cents - 5;
            coins++;
        }
    while  (cents >= 1)
        {
            cents = cents - 1;
            coins++;
        }
    printf("%f\n" , c);
}
1

The issue seems to be you're printing the float variable c as the final input. You seem to only use that variable to get the money owed amount and nothing else.

The variable that stores the answer to the problem is coins.

| improve this answer | |
  • Exactly right!! – Cliff B Jun 30 at 1:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .