#include <cs50.h>
#include <stdio.h>
#include <math.h>
int main(void)
{
// prompts user for amount of change until user enters a valid number
float dollars;
do
{
dollars = get_float("Change:");
}
while (dollars <= 0);
// rounds off change to whole number
int cents = round(dollars * 100);
// calculates change
int count = 0;
while (cents / 25 > 0)
{
count++;
cents = cents - 25;
}
while (cents / 10 > 0)
{
count++;
cents = cents - 10;
}
while (cents / 5 > 0)
{
count++;
cents = cents - 5;
}
while (cents / 1 > 0)
{
count++;
cents = cents - 1;
}
printf("%i\n", count);
return count;
}
Add a comment
|
1 Answer
return count;
A return statement ends a program and returns a value to the operating system. Your code is returning the number of coins to the OS when it should be returning 0 to indicate that it completed successfully.