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

 int main(void)
 {

  float f;
  int y;
                             // User block
  do{
   printf("How much change do you need? ");
   f = (100*get_float());
   y = round(f);
   }
  while ( f < 0 ); 
                            // count greedy

        int amount = y; 
        int coin[] = {25,10,5,1};
        int num;

        for(int i=0; i<coin[i];i++ )
        {
           if(coin[i]<amount) {
           num = amount / coin[i];
           printf("%i\n", num);
           amount -=num*coin[i];
           } 
        } 

how to solve this problem using array ??

0

Notice the output of the sample program in greedy specifications:

~/workspace/pset1 $ ./greedy

O hai! How much change is owed?

0.41

4

The program outputs two, and only two lines. One is "O hai! How much change is owed?" The other one is one line with the number of coins. Your program looks like the following:

~/workspace/pset1 $ ./greedy

How much change do you need? 0.41

1

1

1

Your program outputs 1 + (one through four) lines of code depending on the case. This is because you are printing the amount of every type of coins. What they want is the amount of coins in general.

Instead of printing 1 penny 1 nickle 1 dime

They want 3 coins

| improve this answer | |

You must log in to answer this question.

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