Skip to main content
fixed code formatting
Source Link
Robert S. Pratt
  • 1.9k
  • 1
  • 7
  • 16

can someone tell me why my code doesn't output properly?

include <stdio.h>

include <cs50.h>

include <math.h>

int main(void) { int dollars; do { dollars = get_float("Change owed: "); } while (dollars < 0);

int cents = round(dollars * 100);


int coins = 0;
while (cents >= 25)
{
    cents -= 25;
    coins++;
}

while (cents >= 10)
{
    cents -= 10;
    coins++;
}
while (cents >= 5)
{
    cents -= 5;
    coins++;
}

while (cents >= 1)
{
    cents -= 1;
    coins++;
}
printf("%i\n", coins);

}

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

int main(void)
{
    int dollars;
    do
    {
        dollars = get_float("Change owed: ");
    }
    while (dollars < 0);
    
    int cents = round(dollars * 100);
    
    
    int coins = 0;
    while (cents >= 25)
    {
        cents -= 25;
        coins++;
    }
    
    while (cents >= 10)
    {
        cents -= 10;
        coins++;
    }
    while (cents >= 5)
    {
        cents -= 5;
        coins++;
    }
    
    while (cents >= 1)
    {
        cents -= 1;
        coins++;
    }
    printf("%i\n", coins);
    
}

can someone tell me why my code doesn't output properly?

include <stdio.h>

include <cs50.h>

include <math.h>

int main(void) { int dollars; do { dollars = get_float("Change owed: "); } while (dollars < 0);

int cents = round(dollars * 100);


int coins = 0;
while (cents >= 25)
{
    cents -= 25;
    coins++;
}

while (cents >= 10)
{
    cents -= 10;
    coins++;
}
while (cents >= 5)
{
    cents -= 5;
    coins++;
}

while (cents >= 1)
{
    cents -= 1;
    coins++;
}
printf("%i\n", coins);

}

can someone tell me why my code doesn't output properly?

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

int main(void)
{
    int dollars;
    do
    {
        dollars = get_float("Change owed: ");
    }
    while (dollars < 0);
    
    int cents = round(dollars * 100);
    
    
    int coins = 0;
    while (cents >= 25)
    {
        cents -= 25;
        coins++;
    }
    
    while (cents >= 10)
    {
        cents -= 10;
        coins++;
    }
    while (cents >= 5)
    {
        cents -= 5;
        coins++;
    }
    
    while (cents >= 1)
    {
        cents -= 1;
        coins++;
    }
    printf("%i\n", coins);
    
}
Source Link

pset1 cash please help I'm stuck

can someone tell me why my code doesn't output properly?

include <stdio.h>

include <cs50.h>

include <math.h>

int main(void) { int dollars; do { dollars = get_float("Change owed: "); } while (dollars < 0);

int cents = round(dollars * 100);


int coins = 0;
while (cents >= 25)
{
    cents -= 25;
    coins++;
}

while (cents >= 10)
{
    cents -= 10;
    coins++;
}
while (cents >= 5)
{
    cents -= 5;
    coins++;
}

while (cents >= 1)
{
    cents -= 1;
    coins++;
}
printf("%i\n", coins);

}