0

Could anybody tell me what my mistakes are ?

#include <stdio.h>

#include <math.h>
 

int main (void)
 
{

  float dollar;
      

      do

{

     dollar=get_float("Enter your change :");
}
     

      while (dollar>=0);


  int cents= round (dollar*100);

  int coins=0;


      while (cents>=25)


 {

     cents= cents-25;

     coins++;

 }
    

        while (cents>=10)
 {

     cents= cents-10;

     coins++;

 }
     

     while (cents=cents-5)

 {

     cents= cents-5;


     coins++;

 }
     

     while (cents>=1)

 {

     cents=cents-1;

     coins++;

 }

 

     printf ("You will need at least %i coins", coins);

 
}
$ ./cash


Enter your change0.34

You will need at least 6 coins$ 

$ check50 cs50/problems/2020/x/cash

Connecting.......

Authenticating.....

GitHub username: AnastasiaToskaa

GitHub password: 

Verifying...............

Preparing..............

Uploading................


Waiting for results.....................................................................

Results for cs50/problems/2020/x/cash generated by check50 v3.1.2

:) cash.c exists

:) cash.c compiles

:( input of 0.41 yields output of 4

    Did not find "4\n" in "Enter your cha..."

:( input of 0.01 yields output of 1

    Did not find "1\n" in "Enter your cha..."

:( input of 0.15 yields output of 2

    Did not find "2\n" in "Enter your cha..."

:( input of 1.6 yields output of 7

    Did not find "7\n" in "Enter your cha..."

:( input of 23 yields output of 92

    Did not find "92\n" in "Enter your cha..."

:( input of 4.2 yields output of 18

    timed out while waiting for program to exit

:) rejects a negative input like -1

:) rejects a non-numeric input of "foo" 

:) rejects a non-numeric input of "" 

To see the results in your browser go to 

https://submit.cs50.io/check50/7e964137024d7b7d7c084ee2e266dada2ffb914c
1
  • i got hung up on 0.41 in check50 too, but i also got hung up on 0.01 so i think its not adding that one last penny
    – Aamon Van
    Mar 11 at 4:29
0
do
{
   dollar=get_float("Enter your change :");
}
while (dollar>=0);

Why would you want the loop to repeat when a correct value is input? Also, did you test the program yourself before running check50?

4
  • Yes I did test it, and the output is correct, could you please give me a correct example to my mistake? Nov 14 '20 at 19:09
  • If you tested with this code, you didn't get a correct answer. In fact, you couldn't get any answer at all. THIS code would just keep asking for input until you gave it a negative number.
    – Cliff B
    Nov 14 '20 at 22:59
  • You seem to be mistaken. The code does give correct output. The only problem that I am having is that I can not get the $ to move one line down. Even though I write \n") But the answers as I mentioned before are correct. Nov 15 '20 at 19:42
  • Is it possible that you've been editing and recompiling one version of your code and the code above is another version? It is simply impossible for the code to get past the test condition in the while loop with a positive integer.
    – Cliff B
    Nov 16 '20 at 18:26

You must log in to answer this question.

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