Answer to Question #91214 in C for Aditi

Question #91214
Kesa has changed RS as per unit consumption is one month as per the following condition-

1) unit>=200-> 0.50 paise/unit

2) unit>100 and unit <200->0.60 per/unit

3) unit> 50 and unit<100->0.70 per/unit

4) otherwise 0.8 per/unit

Note- 50 RS meter changes will also add.
1
Expert's answer
2019-07-01T04:57:46-0400

I provided func that return value for month as per the conditions.

double calc(double u) { // u - count of units
	
	if (u >= 200) {
		return 0.5 * u;
	}
	else if (u >= 100 && u < 200) { // && - (and)
		return 0.6 * u;
	}
	else if (u >= 50 && u < 100) {
		return 0.7 * u;
	}
	else {
		return 0.8 * u;
	}
}

Example of test program

#include <iostream>
double calc(double u) { // u - count of units
	
	if (u >= 200) {
		return 0.5 * u;
	}
	else if (u >= 100 && u < 200) { // && - (and)
		return 0.6 * u;
	}
	else if (u >= 50 && u < 100) {
		return 0.7 * u;
	}
	else {
		return 0.8 * u;
	}
}

int main (){
	double un = 60;
	std::cout <<"sum = " << calc(un) << std::endl; 

	un = 40;
	std::cout <<"sum = " << calc(un) << std::endl; 

	un = 150;
	std::cout <<"sum = " << calc(un) << std::endl; 
	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