Answer to Question #119953 in C for ganti

Question #119953
Suppose that a customer in a store bought plates and cups. Write a program that reads
the number of the plates and the price of one plate, the number of the cups and the
price of one cup, and the amount the customer paid. The program should display the
change the customer got back.
1
Expert's answer
2020-06-04T11:03:12-0400
#include <stdio.h>

int main(void) {
  // ask user to enter number of plates and price of one plate
  int platesNum;
  float platePrice;
  printf("Enter number of plates: ");
  scanf("%i", &platesNum);
  printf("Enter price of one plate: ");
  scanf("%f", &platePrice);

  // ask user to enter number of cups and price of one cup
  int cupsNum;
  float cupPrice;
  printf("Enter number of cups: ");
  scanf("%i", &cupsNum);
  printf("Enter price of one cup: ");
  scanf("%f", &cupPrice);

  // ask user to enter amount to pay
  float amount;
  printf("Enter amount to pay: ");
  scanf("%f", &amount);

  // display change
  float sum = (platesNum * platePrice) + (cupsNum * cupPrice);
  if (sum > amount) {
    printf("Not enough amount to pay!");
  } else {
    printf("Your change is: %.2f", amount - sum);
  }

  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS