Enter your age? 48
Enter your gender(m/f)? m
Enter your full name: Barack H Obama
Hello Mr. Barack H Obama
Your membership fee is 302.50 (10% tax included)
Enter your age? 18
Enter your gender(m/f)? f
Enter your full name: Hilary Clinton
Hello Mrs. Hilary Clinton
Your membership fee is 165.50 (10% tax included)
Enter your age? 10
Enter your gender(m/f)? m
Enter your full name: George W. Bush
Hello Mr. George W. Bush
Your membership fee is 55.00 (10% tax included)
so I do that for each one right and name it differently something like this:
No, you do not need to put it in a different variable. They all can go in the same variable.
You just have to put that line in the appropriate if/switch so it will only get executed when the circumstances are correct.
Example:
1 2 3 4 5 6 7 8 9 10 11 12
if( Age < 13 )
{
somevar = CHILDREN_MALE * 0.10; // somevar = 5 if they are less than 13 years old (1-12)
}
elseif( Age < 20 )
{
somevar = TEENAGER_MALE * 0.10; // somevar = 15 if they are 13-19 years old
}
else
{
somevar = ADULT_MALE * 0.10; // somevar = 27.5 if they are 20+ years old
}
EDIT: of course, you will also have to check their gender to choose MALE/FEMALE prices... I didn't want to give you the exact answer.
switch( <expression> )
{
case <possible_value>:
// do something if <expression> == <possible_value>
break;
case <another_possible_value>:
// do something if <expression> == <another_possible_value>
break;
}
Fill in your own info. I don't want to give the direct answer. You should be able to figure it out from there.
You're just copy/pasting my code. If you do that your program will not work correctly. I'm intentionally giving you code that will not work because I don't want you to copy/paste.
The stuff I'm posting is conceptual. It's to show you how these parts of the language work. You have to understand them and adapt them to your problem on your own.
EDIT: My goal is not to solve this problem for you, but to help you understand how if/switch work so that you can solve the problem yourself.
if( Age < 13 )
{
/*
Inside this block of code, you know that the user is between ages 1-12.
So what do you need to do here in order to calculate the cost? How do you calculate the
cost for a 1-12 year old?
*/
}