Hei, I'm currently stuck on this Greedy.c project. it says that my while loop is empty, which it's not? Can someone give me a hint towards, what is wrong with my code? Thank you.
#include <cs50.h>
#include <stdio.h>
#include <math.h>
int main(void)
{
// Declare variables
int amount = 0;
float dollars;
// Get amount of dollars owed
do{
printf("How much money is owed: \n");
dollars = GetFloat();
} while (dollars < 0); {
printf("Input is invalid!\n");
}
// Convert to cents
float convert_to_cents = 100 * dollars;
int cents = round(convert_to_cents);
printf("%d cents\n", cents);
// While loops, check for coins
while (cents > 24); {
amount + 1;
cents = cents % 25;
}
while (cents > 9); {
amount++;
}
while (cents > 4); {
amount++;
}
while (cents > 0); {
amount++;
}
// Print total amount of coins used
printf("The total amount of coins used is: %d\n",amount);
}
Edit: So i've fixed the while loops, and it's looking to work as it should.
#include <cs50.h>
#include <stdio.h>
#include <math.h>
int main(void)
{
// Declare variables
int amount = 0;
float dollars;
// Get amount of dollars owed
do{
printf("How much change is owed: \n");
dollars = GetFloat();
} while (dollars < 0);
if (dollars <= 0 || ""){
printf("Input is invalid\n");
}
// Convert to cents
float convert_to_cents = 100 * dollars;
int cents = round(convert_to_cents);
printf("%d cents\n", cents);
// While loops, checking for coins
while (cents > 24) {
amount++;
cents = cents - 25;
}
while (cents > 9) {
amount++;
cents = cents - 10;
}
while (cents > 4) {
amount++;
cents = cents - 5;
}
while (cents > 0) {
amount++;
cents = cents - 1;
}
// Print total amount of coins used
printf("The total amount of coins used is: %d\n",amount);
}