In: Computer Science
This assignment is one program demonstrating IF statements and Decisions in C++ format.
Program 2 People eating at a restaurant get to eat for free if they are younger than 10, pay full price if they are under 65, get a $3 discount if they are 65 or over. Write a program asking the user for an age of the next customer and the price of the food they ordered. Calculate how much to charge based on the price (set to 0, full price, or with a discount) along with a 15% tip. Then have the program show this amount to the user. Examples: What age is the person 5 What price is the meal 10 The charge for this person is 0 (a second program run) What age is the person 70 What price is the meal 10 The charge for this person is 8.05
Code:
#include<iostream>
using namespace std;
int main()
{
int age;
float price,final_charge;
cout << "What age is the Person : ";
cin >> age;
cout << "What price is the Meal : ";
cin >> price; //taking age and price of the meal
from user
if (age<10) //if age<10 final_charge=0
{
final_charge=0;
}
else if (age>=10 && age<65) //if
age>=10 and age<65 then full price+ 15% tip
{
final_charge=price+(price*0.15);
}
else if (age>=65) //if age greater than 65 then
price+15% tip and 3 dollars discount
{
final_charge=price+(price*0.15)-3;
}
cout << "The charge for this person is "
<< final_charge << endl; //finally print the
final_charge
return 0;
}
Code and Output Screenshots:
Note : if you have any queries please post a comment thanks a lot..always available to help you...