please help

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

your Total cost after discound is: 148

press any key to continue . . .


thank you

Can you show us what you have so far?
cannot write code
and i did my best with it but it does not run with me and i don't know why!?
Last edited on
Write a complete C++ program
1
2
3
4
int main(void)
{
    return 0;
}

Now your turn to write a complete C++ program which calculates the cost of an adult ticket without a meal. When that works, you can add another part.

Or you could write a complete C++ program which gives the first line of the sample output.
People will not do homework for you. You must show some sort of effort. At least tell us where you get "stuck" at.

I will give you a sample c++ "Hello World!" to get you started:
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
using namespace std;

int main() {
    cout << "Hello World!" << endl;
    cout << "Type a number, the press enter: ";
    int num;
    cin >> num;
    cout << "You entered " << num << "." << endl;
    cout << "GoodBye" << endl;
    return 0;
}
#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.
Last edited on
unintialized local k
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?
Last edited on
i don't know what write in [switch]
See http://www.cplusplus.com/doc/tutorial/control/. The switch statement is described at the bottom. After reading that, if you have questions, ask.

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.
Last edited on
change:
1
2
cout<<"welcome the tairn ticket cost calculator,\nHow old are you?"<<age;
cin>>age;


to:
1
2
cout<<"welcome the tairn ticket cost calculator,\nHow old are you?";
cin>>age;
Topic archived. No new replies allowed.