Basic PAGE16 Exercises 1-5 Discount

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.