0

I am getting the desired number of cents however when I am submitting I am getting the below error :(. I tried to do some research but still not able to find the fault. Please check. Thank you!.

:( input of 1.6 yields output of 7
expected exit code 0, not 1
Log
running ./cash...
sending input 1.6...
checking for output "7\n"...
checking that program exited with status 0...
:( input of 23 yields output of 92
expected exit code 0, not 23
Log
running ./cash...
sending input 23...
checking for output "92\n"...
checking that program exited with status 0...

this is my code:

#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main(void) 
{
    float dollars;
    do
    {
         dollars = get_float("Change: ");
    }    
    while ( dollars <= 0);
//the computation formula to get cents and remainder
         int coins = round(dollars * 100);
         int twentyfive = round(coins / 25);
         int twentyfiveremainder = coins % 25;
         int ten = round(twentyfiveremainder / 10);
         int tenremainder = twentyfiveremainder % 10;
         int five = round(tenremainder / 5);
         int fiveremainder = tenremainder % 5;
         int one = round(fiveremainder / 1);
 //The if-else if condition for computing the cents
    if (coins % 25 == 0)
    {
        printf("%i\n", twentyfive);
    }
    else if (twentyfiveremainder % 10 == 0)
    {
        int totalcoins = twentyfive + ten;
        printf("%i\n", totalcoins); 
    }
     else if (tenremainder % 5 == 0)
    {
        int totalcoins = twentyfive + ten + five;
        printf("%i\n", totalcoins);
    }
     else if (fiveremainder % 1 == 0)
    {
        int totalcoins = twentyfive + ten + five + one;
        printf("%i\n", totalcoins);
    }
    return dollars;  
    exit(0);
}

1

This return dollars; ends execution of the main function, and is, for all intents and purposes, the exit status.

1
  • thanks for the hint! I'm now able to get the desired output by rectifying return dollars; – Jean-Pierre de Villeres Jan 17 '20 at 13:01

You must log in to answer this question.

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