Been working on the homework assignment for the edxCS50 course, and still pretty new at C and programming so I was pretty proud to finally get this to compile. But the final result seems like I'm missing something somewhere
The point of the code is to take the user inputted money, and spit out the minimum amount of coins necessary to make that money. The idea was to first convert everything to integers so I could use modulo. If the amount entered was divisible by 25, then that's the end of it and it would divide by 25 to get amount of quarters needed. If not then it would find out how many quarters there are, find the remainder, use it as the remaining change, and rinse and repeat until you get to pennies. At the end it's supposed to add up the amount of coins and spit it out.
The problem is every single time I run it, the end sum results in a big fat "0" . I'm pretty sure it's because the variables remain at the starting value of 0 but I can't figure out why it's not changing the variable values as the code is being run.
First time posting here so feel free to correct me if I'm not specific enough or missing info in this post
#include <stdio.h>
#include <cs50.h>
int main(void)
{float moneytotf=0.0;
int moneytot= moneytotf*100;
int qtr=0;
int dime=0;
int nickel=0;
int penny=0;
int change;
do
{
printf("O hai! How much change is owed?\n");
moneytotf=get_float();
}
while (moneytot<0);
if (moneytot%25==0)
{qtr=moneytot/25;}
else
{if (moneytot/25<1)
{qtr=0;}
else
{
qtr=(moneytot-moneytot%25)/25;
change=moneytot%25;
if (change%10==0)
{dime=change/10;}
else
{if (change/10<1)
{dime=0;}
else
{dime=((change-change%10)/10);
change=change%10;
if (change%5<1)
{
nickel=0;
}
else
{
if ((change-5)<1)
{nickel=0;}
else
{nickel=((change-change%5)/5);
change=change%5;
if (change==0)
{
penny=0;
}
else
{penny=change;}
}
}
}
}
}
}
int sum = qtr+dime+nickel+penny;
printf("%i\n", sum);
}