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

int main(void) {
float change;
int quarter = 25;
int dime = 10;
int nickel = 5;
int penny = 1;
int counter = 0;
int c;
//user input
do {
  printf("O hai! How much change is owed?\n");
  change = get_float();
} while (change < 0);
//converting to cents
c = change * 100;
//calculating coins
while (c > quarter) {
  counter++;
  c = c - quarter;
}
while (c > dime) {
  counter = counter + 1;
  c = c - dime;
}
while (c > nickel) {
  counter = counter + 1;
  c = c - nickel;
}
while (c > penny) {
  counter = counter + 1;
  c = c - penny;
}
printf("Coins are %i", counter);
}

Still not working help?

0

There are several problems. First, c is created and later populated with the number of cents, but then never used.

Next, all the while loops based on change have issues with the setup statements. Remember that a while loop runs until the test condition is false, not until it becomes true.

There may be other issues, but this will get you started. Just take some time and reread your code, thinking about what each line does and how each var is used in that line and later.

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

2
  • Can you look into it again,made some changes. Dec 27 '17 at 15:04
  • Have you tested it? What doesn't work? If you're having a new problem, you should create a new question instead of replacing the code in the original question. The edited question will no longer match the answer and will confuse anyone that looks at it in the future.
    – Cliff B
    Dec 28 '17 at 2:58

You must log in to answer this question.

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