current position:Home>C language function problem, confusion,.?!

C language function problem, confusion,.?!

2022-02-03 01:13:38 CSDN Q & A

A shopping mall launched a discount promotion : If the customer is dissatisfied with the amount of shopping 100 Yuan is not a discount ; To achieve or surpass 100 15% discount for yuan ; To achieve or surpass 200 10% discount for yuan ; To achieve or surpass 500 15% discount for yuan ; To achieve or surpass 1000 20% discount for yuan . Please write a function , Calculate the actual payment amount after discount according to the shopping amount .

The function prototype
double Cash(double value);
explain : Parameters value The amount of shopping for customers , The function value is the actual payment amount after discount .

judging procedures
#include <stdio.h>

double Cash(double value);

int main()
{
double p, c;
scanf("%lg", &p);
c = Cash(p);
printf("%.2f\n", c);
return 0;
}




Refer to the answer 1:
double Cash(double value){    if(value>=1000){        value*=0.8;    }else if(value>=500){        value*=0.85;    }else if(value>=200){        value*=0.9;    }else if(value>=100){        value*=0.95;    }    return value;}



Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202030113361036.html

Random recommended