0

So I am very new to CS and I have been working hard twisting this code around in my mind trying to figure out why nothing happens when I run the program. It compiles fine, but whenever I put in any input...nothing. I think I may be getting stuck in a while loop? I don't really have enough knowledge to verify that statement though, so here is my code:

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

int main(void)
{
    float change; int coins;
    int q; int d; int n; int p;

{
    change = get_float("Enter Amount: ");
    change = round(change * 100);
}
while(change < 0);

while(change > 0)
{
    coins = 0;
    q = 25;  d = 10;
    n = 5;  p = 1;
}
if(change >= q)
{
    change = change - q; 
    coins++;
}
else if(change >= d)
{
    change = change - d;
    coins++;
}
 else if(change >= n)
 {
    change = change - n;
    coins++;
 } 
 else
 {
    change = change - p;
    coins++;
 }
 if (change == 0)
 {
    printf("You will need:%i coins\n", coins);
 }
 }
0

Look at this code snipet:

while(change > 0)
{
    coins = 0;
    q = 25;  d = 10;
    n = 5;  p = 1;
}

This is an infinite loop. Once the loop starts, the value in change is never altered. So, if the loop starts running, it will never stop.

There may be other questions, but those would be for new questions.

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

You must log in to answer this question.

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