I wrote this following code as solution to the pset1 cash problem, it compiles and runs but once the user inputs the owed amount it replies with 0 coins to give back, which is false.
#include <stdio.h>
#include <cs50.h>
#include <math.h>
//declaration of global variables
float owed;
int coins;
//main function for gathering user input and outputting amount of owed coins
int main(void)
{
do
{
owed = get_float("How much do i owe ya'?\n");
}
while (owed < 0);
printf("Here's your change! %i coin(s)!\n", coins);
}
// here i'm checking owed value and comparing to each coins' value, and then //comparing to the amount of coins to give back
int math(void)
{
int cents = owed * 100;
while (cents % 25 == 0)
{
cents = cents - 25;
coins++;
}
while (cents % 10 == 0)
{
cents = cents - 10;
coins++;
}
while (cents % 5 == 0)
{
cents = cents - 5;
coins++;
}
while (cents % 1 == 0)
{
cents = cents - 1;
coins++;
}
return 0;
}
What am i doing wrong? I'm thankful for any tips, been thinking about this for a day or two now.