For some reason sometimes it gets the answers right and others it gets the answer wrong, I'm stuck so I don't know what to do next.
#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main(void) {
float dollars;
do {
dollars = get_float("Change Owed: \n");
}
while (dollars < 0);
int cents = round(dollars * 100);
int counter = 0;
int counterQ = 0;
int counterD = 0;
int counterN = 0;
int counterP = 0;
for (int quarter = 0; quarter < cents; quarter += 25) {
counterQ++;
}
for (int dime = 0; dime < (cents - (counterQ*25)); dime += 10) {
counterD++;
}
for (int nickel = 0; nickel < (cents - (counterQ*25) - (counterD*10)); nickel += 5) {
counterN++;
}
for (int penny = 0; penny < (cents - (counterQ*25) - (counterD*10) - (counterN*5)); penny += 1) {
counterP++;
}
counter = (counterQ + counterD + counterN + counterP);
printf("%i\n", counter);
}
.26
(26 cents) will give two coins, which looks ok, but they will both be quarters.