0

I have finish my cash homework enter link description here But I face an issue that I can't check it even when I run the program successfully. My code is as below:

    #include <stdio.h>
    #include <cs50.h>
    int main(void)
    {
    int x;
    
    
      x=0;
       int amount=get_int("Change owed:");
    
      do{
        while(amount>=25){
         amount=amount-25;
         x++;
        }
        while(amount>=10 && amount<25){
         amount=amount-10;
         x++;
        }
    
        while(amount>=5 && amount<10){
         amount=amount-5;
         x++;
        }
        while(amount>=1 && amount<5){
         amount=amount-1;
         x++;
        }
    
        }while(amount>0);
      printf("%d \n",x);
    
    
    
    }

I have try to test the code use scanf instead of get_int which shown as follow:

#include <stdio.h>
#include <cs50.h>
#int main(void)
{
    int amount,no;
  amount=0;
  no=0;
   printf("Change owed: ");
   scanf("%d",&amount);

  do{
    while(amount>=25){
     amount=amount-25; 
     no++;
    }
    while(amount>=10 && amount<25){
     amount=amount-10; 
     no++;
    }

    while(amount>=5 && amount<10){
     amount=amount-5; 
     no++;
    }
    while(amount>=1 && amount<5){
     amount=amount-1; 
     no++;
    }
  
  
    }while(amount>0);
  printf("%d",no);
  
 
    
}

I have check both code using check50 cs50/problems/2022/x/cash it shown errors as below

:) cash.c exists
:( cash.c compiles
    code failed to compile
:| get_cents returns integer number of cents
    can't check until a frown turns upside down
:| get_cents rejects negative input
    can't check until a frown turns upside down
:| get_cents rejects a non-numeric input of "foo" 
    can't check until a frown turns upside down
:| calculate_quarters returns 2 when input is 50
    can't check until a frown turns upside down
:| calculate_quarters returns 1 when input is 42
    can't check until a frown turns upside down
:| calculate_dimes returns 1 when input is 10
    can't check until a frown turns upside down
:| calculate_dimes returns 1 when input is 15
    can't check until a frown turns upside down
:| calculate_dimes returns 7 when input is 73
    can't check until a frown turns upside down
:| calculate_nickels returns 1 when input is 5
    can't check until a frown turns upside down
:| calculate_nickels returns 5 when input is 28
    can't check until a frown turns upside down
:| calculate_pennies returns 4 when input is 4
    can't check until a frown turns upside down
:| input of 41 cents yields output of 4 coins
    can't check until a frown turns upside down
:| input of 160 cents yields output of 7 coins
    can't check until a frown turns upside down

What can I do to solve this problem, please tell me thanks.

0

1 Answer 1

1

Warning on Cash problem

It pays to read this if you missed it. It explains why your program will not compile.

1
  • Thanks for your answer, I found that I miss the criteria in the implementtation detail after reading the guide . May 4 at 13:29

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