Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <stdio.h> int main(void) ( int hundred_dollars; int fifty_dollars; int

ID: 3587356 • Letter: #

Question

#include <stdio.h>
int main(void)

(
    int hundred_dollars;
    int fifty_dollars;
    int twenty_dollars;
    int ten_dollars;
    int five_dollars;
    int one_dollar;
    int quarters;
    int dimes;
    int nickels;
    int pennies;
    float dollars;
    int cents;

    printf("Please enter an amount in dollars. A negative number will terminate the program. ");
    scanf("%f", &dollars);
    while(dollars>=0);
(
    cents=(dollars+.005)*100;

    hundred_dollars=cents/10000;
    cents=cents%10000;
    fifty_dollars=cents/5000;
    cents=cents%5000;
    twenty_dollars=cents/2000;
    cents=cents%2000;
    ten_dollars=cents/1000;
    cents=cents%1000;
    five_dollars=cents/500;
    cents=cents%500;
   >     cents=cents%100;
    quarters=cents/25;
    cents=cents%25;
    dimes=cents/10;
    cents=cents%10;
    nickels=cents/5;
    cents=cents%5;
    pennies=cents;

printf("%f dollars consists of the following bills and coins: ", dollars);
    printf("The number of hundred dollar bills is: %d ", hundred_dollars);
    printf("The number of fifty dollar bills is: %d ", fifty_dollars);
    printf("The number of twenty dollar bills is: %d ", twenty_dollars);
    printf("The number of ten dollar bills is: %d ", ten_dollars);
    printf("The number of five dollar bills is: %d ", five_dollars);
    printf("The number of one dollar bill is: %d ", one_dollar);
    printf("The number of quarters is: %d ", quarters);
    printf("The number of dimes is: %d ", dimes);
    printf("The number of nickels is: %d ", nickels);
)
   return 0;
)


Can anybody help me with what I need to do to correct this program and for it to run properly? I don't understand why this is wrong! Thanks! ALSO: This is Computer Language C!

Explanation / Answer

I have written comments where errors present in your program please check

#include <stdio.h>
int main(void)

( //// replace this brace with '{' because for function starting normally flower brace are used
    int hundred_dollars;
    int fifty_dollars;
    int twenty_dollars;
    int ten_dollars;
    int five_dollars;
    int one_dollar;
    int quarters;
    int dimes;
    int nickels;
    int pennies;
    float dollars;
    int cents;

    printf("Please enter an amount in dollars. A negative number will terminate the program. ");
    scanf("%f", &dollars);
    while(dollars>=0); //semicolon is not needed because with out semicolon only control will enter the loop replace this with while(dollars>=0) and this loop might result in a infinite as variable dollars is not decremented.
( //// replace this brace with '}' because for loop startingnormally flower braces are used
    cents=(dollars+.005)*100;

    hundred_dollars=cents/10000;
    cents=cents%10000;
    fifty_dollars=cents/5000;
    cents=cents%5000;
    twenty_dollars=cents/2000;
    cents=cents%2000;
    ten_dollars=cents/1000;
    cents=cents%1000;
    five_dollars=cents/500;
    cents=cents%500;
   >     cents=cents%100;
    quarters=cents/25;
    cents=cents%25;
    dimes=cents/10;
    cents=cents%10;
    nickels=cents/5;
    cents=cents%5;
    pennies=cents;

printf("%f dollars consists of the following bills and coins: ", dollars);
    printf("The number of hundred dollar bills is: %d ", hundred_dollars);
    printf("The number of fifty dollar bills is: %d ", fifty_dollars);
    printf("The number of twenty dollar bills is: %d ", twenty_dollars);
    printf("The number of ten dollar bills is: %d ", ten_dollars);
    printf("The number of five dollar bills is: %d ", five_dollars);
    printf("The number of one dollar bill is: %d ", one_dollar);
    printf("The number of quarters is: %d ", quarters);
    printf("The number of dimes is: %d ", dimes);
    printf("The number of nickels is: %d ", nickels);
) // replace this brace with '}' because for loop ending normally flower braces are used
   return 0;
)// replace this brace with '}' because for functions ending normally flower braces are used

Please find the modified program below which will execute correctly:

#include <stdio.h>
int main(void)
{
int hundred_dollars;
int fifty_dollars;
int twenty_dollars;
int ten_dollars;
int five_dollars;
int one_dollar;
int quarters;
int dimes;
int nickels;
int pennies;
float dollars;
int cents;
printf("Please enter an amount in dollars. A negative number will terminate the program. ");
scanf("%f", &dollars);
while(dollars>=0)
{
cents=(dollars+.005)*100;
hundred_dollars=cents/10000;
cents=cents%10000;
fifty_dollars=cents/5000;
cents=cents%5000;
twenty_dollars=cents/2000;
cents=cents%2000;
ten_dollars=cents/1000;
cents=cents%1000;
five_dollars=cents/500;
cents=cents%500;
> cents=cents%100;
quarters=cents/25;
cents=cents%25;
dimes=cents/10;
cents=cents%10;
nickels=cents/5;
cents=cents%5;
pennies=cents;
printf("%f dollars consists of the following bills and coins: ", dollars);
printf("The number of hundred dollar bills is: %d ", hundred_dollars);
printf("The number of fifty dollar bills is: %d ", fifty_dollars);
printf("The number of twenty dollar bills is: %d ", twenty_dollars);
printf("The number of ten dollar bills is: %d ", ten_dollars);
printf("The number of five dollar bills is: %d ", five_dollars);
printf("The number of one dollar bill is: %d ", one_dollar);
printf("The number of quarters is: %d ", quarters);
printf("The number of dimes is: %d ", dimes);
printf("The number of nickels is: %d ", nickels);
}
return 0;
}

note : in while loop i didnt increment dollars variable if you need to run an infinite loop no need to add dollars-- before the end of the loop or else add dollars-- to correctly exit the while loop and program and also check whether the floating point variable can be used for increment or decrement operations.