Title: A garment 95 yuan, if the consumption of 300 yuan, can play 85 percent. Enter the number of clothes purchased, output the amount (in units) to be paid, and retain two decimal places.
The branch structure allows you to determine whether to call 85 percent.
(1) Declaration of the number of clothing pieces A, the amount to be paid B:
int A; // A is the number of clothing pieces double b; // B is the amount to be paid
(2) Enter a:
scanf ("%d", &a);
(3) through If...else ... Or...? ...:... Determine whether the total amount is equal to 300, if the big and 300 will hit 85 percent:
if (A* >=) b= (double) A **0.85; Else B= (double) a*;
Or:
b=a*>=? (double) a*0.85: b= (double) A *;
(4): Output B:
printf ("%.2lf", b);
Complete.
Blog and code copyright belongs to AbelIvan7, qq:2902408434
Full code:
//Blog and code copyright belongs to AbelIvan7, qq:2902408434//P16 Exercise 1-5 Discount#include <cstdio>intA//A is the number of clothing piecesDoubleb//B is the amount to be paidintMain () {scanf ("%d",&a); if(A * the>= -) b=(Double) A * the*0.85; Elseb=(Double) A * the; //b=a*95>=300? (double) a*95*0.85:b= (double) a*95;printf ("%.2LF", B); return 0; }
Basic PAGE16 Exercises 1-5 Discount