i have a qestion and i have just one day to answer it ,so i really need your help..
here is it
Write a complete C++ program that calculates the cost of train ticket as the following,
If the passenger is an adult (i.e. +17 years old) his ticket costs 150 $,
If the passenger is a kid (i.e. 16~3 years old) his ticket costs 80 $,
If the passenger is a baby (i.e. less than 2 years old) his ticket costs 40 $,
Also, if the passenger wants a meal on the train it cost for the adult is 25 $, 15 $ for the kids meal and the baby meal is for free.
If the passenger has a discount coupon he gets 15% off the total cost.
in this questio i should only use if statment or switch
Here is a sample output:
welcome to the train tickett cost calculator,
How old are you? 22
Tickets for adults cost 150 $ without a meal,
Do you want a meal?(y/n) y
The meal will cost 25 $, your total is < 175 $ >
Do you have a discount copone? (y/n) y
#include<iostream>
using namespace std;
int main()
{
int age , k;
cout<<"welcome the tairn ticket cost calculator,\nHow old are you?"<<age;
cin>>age;
if(age>=17)
cout<<"Tickts for adults cost 150$ without a meal,\n Do you want a meal?(y/n)";
switch(k)
{
case 'y': cout <<"the meal will cost 25 $ ,your total is"<< k=150+25<<endl;
cout<<"do you have a discount copone?(y/n)"
k=k-(k*0.15);
cout<<"your total cost after discount is"<<k<<endl;
When you compile the above, what error messages do you get?
When posting code, please use code tags. See the <> button to the right. That will keep your indentation intact. If you do not have indentation, please pick an indentation style and use it consistently.
You seem to be missing an input statement after your prompt that include
Do you want a meal?
What do you want to store in k? Consider changing the name of k to reflect what you want to store in it. What type is k? Does that type make sense for the information which you want to store in k?
What do you want the switch statement to do for you?
Consider just asking for the age and if they want a meal [edit] and have a discount coupon[/edit]. Then calculate the cost. The display the cost.
For your first version, consider just using a fixed value for the cost. Then you can debug the input and output statements without concern for the calculation.