0

I've been struggling with this for a month now so any help will be appreciated.

The program just returns the value of input, so although there are no errors in compiling, it doesnt actually produce anything meaningful. Thanks for your help!

#include <cs50.h>
#include <stdio.h>
#include <math.h>

//DECLARE THE VALUES//

int main (void) 
{
float money;
//counts coins 
int coins = 0;

//INPUT//

do
 {
    money = get_float ("Change owed:\n");
}
//Don't accept negative values 
while (money>0);
printf("foo");

//convert float into int
coins = round (money * 100);

//Quarters

while (money>=25)
 {    
  money -= 25;
    coins++;
printf("%i\n", coins);
 }
//Dimes 

while (money>=10)
 { 
    money -= 10;
    coins++;
    printf("%i\n", coins);
}

//Nickels
while (money>=5)
 { 
    money -= 5;
    coins++;
    printf("%i\n", coins);
}


//Pennies 

while (money>=1)
 { 
    money -= 1;
    coins++;
    printf("%i\n", coins);
}

}
0

Sorry to hear you've been fighting this for so long.

The do/while loop will never accept a value greater than zero because of the test. You want the loop to repeat only when the input value is negative. Otherwise, it'll just ask you for valid data over and over again. Think of the while loop test as a negative test.

That should get you going.

If this answers your question, please click on the check mark to accept.Let's keep up on forum maintenance. ;-)

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .