The Help With Assignment Blog is intended to provide with tips and tricks to students so that they are able to do better at school and college. The Blog is associated with HelpWithAssignment.com (HwA), a leading provider of online tuitions in University subjects.

Tuesday, February 1, 2011

C++ Programming Help at HelpWithAssignment.com (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 <= 100)
{
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 http://www.helpwithassignment.com/ http://www.helpwithassignment.com/programing-assignment-help
This is in continuation with our previous articles on C++ and C++ Assignment help

1 comment:

Anonymous said...

Great post Surya... keep it up!