C++ Programming Help (If Else Statement Example)
Here is an example of an If Else statement example. Here the situation is sales in a company. If 100 units are sold then, $0.25/unit is awarded to the sales executives and if the sales are more than 100 then for the additional units sold an additional incentive of $0.15 is given.
#include
using namespace std;
void main()
{
unsigned int Miles;
const double LessThan100 = 0.25;
const double MoreThan100 = 0.15;
double PriceLessThan100, PriceMoreThan100, TotalPrice;
cout << “Enter the number of miles: “; cin >> Miles;
if(Miles {
PriceLessThan100 = Miles * LessThan100;
PriceMoreThan100 = 0;
}
else
{
PriceLessThan100 = 100 * LessThan100;
PriceMoreThan100 = (Miles – 100) * MoreThan100;
}
TotalPrice = PriceLessThan100 + PriceMoreThan100;
cout << “\nTotal Price = $” << TotalPrice << “\n\n”;
}
Here in the program we can see that here two constants are initiated with called the “LessThan100” and “MoreThan100”. In the first case when the sales reach up to 100 then the employee is awarded an incentive of $0.25/unit sold, which means if the sales are 85 units then the incentive would be 85 * 0.025 = 21.25.
On the other hand if the sales are more than 100 then the first 100 units are paid $0.25 and the additional units are paid $0.15. This is done by subtracting the 100 from the total sales, multiplying the 100 units with the $0.25 and the additional units is multiplied with $0.15. this gives the total incentive. For example if the sale is 135 units then the incentive would calculated as 135-100 = 35; 100 *0.25 = 25 and 35 * 0.15 = 5.25; the total incentive would be 25+5.25 = 30.25.
At HelpWithAssignment.com we provide the best quality Assignment help, Homework help and Online Tutoring in C++ and other Programming languages for College and University students. For more details visit our website at https://www.helpwithassignment.com/programing-assignment-help
This is in continuation with our previous articles on C++ and C++ Assignment help
Book Your Assignment
Recent Posts
How To Prepare An Excellent Thesis Defense?
Read MoreHow to Restate A Thesis? – A Detailed Guide
Read MoreExplanatory Thesis: Examples and Guide for Clear Writing
Read MoreHow To Write 3 Types Of Thesis Statements?
Read MoreHow to Effectively Prepare for Your Thesis Defense?
Read MoreGet assignment help from subject matter experts!
4.7/5 rating | 10,000+ happy students | Great tutors 24/7