I have a problem with my code for "greedy.c". Essentially, the user is asked to enter an amount, but when the user enters an amount other than 0, the program stops and does not function any further, and I have to exit it using Ctrl-C. I have tried this using the Ubuntu host and the CS50 appliance, and the same crashing behaviour happens on both.
Here is the snippet of the code that I think is causing the problem. I reckon myself that the code is valid (but it may be that I've mainly programmed before in Java), but there may be an error in it that stops it from working.
#include <cs50.h>
#include <stdio.h>
int main(void)
{
float amount = 0;
while (amount <= 0) {
printf("Change owed = $");
amount = GetFloat();
printf("%G", amount);
}
While the user is able to input the floating-point number, the program hangs, and the amount is not printed afterwards, like it is supposed to do.
Honestly, I have no idea why this is not working, but if anyone can help me, this will be appreciated.
Many thanks in advance, Jack