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

C code 1. The user enters a dollar amount up to $200.00. The input is double and

ID: 3542126 • Letter: C

Question

C code


1. The user enters a dollar amount up to $200.00. The input is double and decimal places are used to represent cents.

    if the user types in more than two decimal places remove the extra places.

2. The $200.00 limit must be strictly enforce. If the user enters a larger value or a negative value, make them re-enter( with a prompt) until an

   acceptable value is input

3. Once an acceptable dollar amount is entered, your program will compute and display the amount entered, followed by a proper breakdown

  of denominations that represent that dollar amount, using the largest denominations possible. The following denominations are used:

   $ 20,  $10, $5, $1, .25, .10, .05, .01

4 If a denomination is not used, do not display that denomination at all

5 Have your results read singular or plural as appropiate(ex "1 $20.00", "2 $20.00s"

6 After the breakdown has been output, ask the user if they want to enter another value to breakdown , If they answer yes have them repeat the above

  process



Example

Amount entered: $55.41


Change

2 $20.00s

1 $10.00

1   $5.00

1        .25

1        .10

1        .05

1         .01

Explanation / Answer

#include<stdio.h>

#include<conio.h>


int main(){

float amount;

int num, i = 0;

float arr[8] = {20.00, 10.00, 5.00, 1.00, 0.25, 0.10, 0.05, 0.01};

printf("Amount entered: ");

scanf("%f", &amount);


if(amount > 200.00 || amount < 0.00) main();

printf("Change ");

while(amount >= 0.01){

num = amount / arr[i];

float x = num;

amount = amount - (x * arr[i]);

if(num == 1){

printf("1 ");

if(arr[i] >= 1.00)printf("$");

printf("%.2f ", arr[i]);

}


if(num > 1){

printf("%d ", num);

if(arr[i] >= 1.00)printf("$");

printf("%.2fs ", arr[i]);

}

i++;

}

char c;

printf("Want to enter more?? y fro yes/ n for no :");

c = getch();

if(c == 'y') main();

else return 0;

return 0;

}