Stuck on switch menu options?

Pages: 123
So far I have this but don't know how to make Age between 13-19??

Output is supposed to look like this with three of these instead of two:

1
2
3
4
5
6
7
8
9
10
11
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)



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream> 
#include <iomanip> 
#include <string>

using namespace std;

const float CHILDREN_MALE=50.00;
const float CHILDREN_FEMALE=55.00;
const float TEENAGERS_MALE=150.00;
const float TEENAGERS_FEMALE=155.00;
const float ADULTS_MALE=275.00;
const float ADULTS_FEMALE=250.00;

int main()
{
	int Age, name;
	float Mcost=0.0;
	float total=0.0; 
	char gender;
	cout << fixed << showpoint << setprecision (2);
	
	//Display Menu
	cout << "-------------Fullerton Health Club--------------" << endl;
	cout << "Children (Age 1-12) " << endl;
	cout << setfill ('.');
	cout << left << setw(15) << "\tMale" << right << setw(6) << CHILDREN_MALE << endl; 
	cout << left << setw(15) << "\tFemale" << right << setw(6) << CHILDREN_FEMALE << endl; 
	cout << "Teenagers (Age 13-19)" << endl;
	cout << left << setw(15) << "\tMale" << right << setw(6) << TEENAGERS_MALE << endl;
	cout << left << setw(15) << "\tFemale" << right << setw(6) << TEENAGERS_FEMALE << endl;
	cout << "Adults (Age > 19)" << endl; 
	cout << left << setw(15) << "\tMale" << right << setw(6) << ADULTS_MALE << endl;
	cout << left << setw(15) << "\tFemale" << right << setw(6) << ADULTS_FEMALE << endl;

	//Ask for age, gender, and full name
	cout << "Enter your age? "; 
	cin >> Age; 
	cout << "Enter your gender(m/f)? ";
	cin >> gender; 
	cout << "Enter your full name: "; 
	cin >> name; 
	cout << "  Hello" << (gender == 'm' ? " Mr. " : " Mrs.") << name << "," << endl;
	
	cout << "Your membership fee is " << float (Mcost) << "(10% tax is included)" << endl;  

	switch(Age<12)
	{
		case 'm': case 'M': (CHILDREN_MALE*.10); 
		case 'f': case 'F': (CHILDREN_FEMALE*.10); 
    }
	{
		switch(Age<12)
		{
		case 'm': case 'M': (TEENAGERS_MALE*.10); 
		case 'f': case 'F': (TEENAGERS_FEMALE*.10); 
		}
	}
	system ("pause");
	return 0; 
}
Last edited on
Please put your code inside of [code] tags.

That said... this block of code makes absolutely no sense:
1
2
3
4
5
6
7
8
9
10
11
12
switch(Age<12)
{
  case 'm': case 'M': (CHILDREN_MALE*.10);
  case 'f': case 'F': (CHILDREN_FEMALE*.10);
}
{
  switch(Age<12)
  {
    case 'm': case 'M': (TEENAGERS_MALE*.10);
    case 'f': case 'F': (TEENAGERS_FEMALE*.10);
  }
}


What are you trying to accomplish here?
1
2
3
4
5
6
7
8
9
10
11
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)
do I use for(i=1, i<19, ++i) ?
I have to select an option from the menu:

It looks like this right now but it's supposed to be like the one above:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Children (Age 1-12)
        Male...........50.00
        Female.........55.00
Teenagers (Age 13-19)
        Male..........150.00
        Female........155.00
Adults (Age > 19)
        Male..........275.00
        Female........250.00
Enter your age? 48
Enter your gender(m/f)? m
Enter your full name: Barack
  Hello Mr. -858993460,
Your membership fee is 0.00(10% tax is included)
Press any key to continue . . .
Okay, well you have a few problems here.

A switch statement works like so:

1
2
3
4
5
6
7
8
9
10
switch( <expression> )
{
   case <possible_value>:
      // do something if <expression> == <possible_value>
      break;

   case <another_possible_value>:
      // do something if <expression> == <another_possible_value>
      break;
}


You seem to be confusing a switch with an if statement. Look at what you have here:

1
2
3
switch(Age<12)
{
  case 'm': case 'M': (CHILDREN_MALE*.10);


Your expression is Age < 12, which will be either true if they're younger than 12, or false if they're not. This means you can realistically only have 2 cases because there are only 2 possible values: true and false.

However you have 4 values: 'm', 'M', 'f', and 'F' -- which of course is nonsensical because Age<12 cannot be 'm'. So you seem to be mixing up gender with age.

This would make much more sense:

1
2
3
switch(gender)
{
   case 'm': case 'M':  //... 


The expression here is 'gender'... which could be 'm', 'M', 'f', or 'F'. So now your cases make sense.

You probably want to put the age check in an if statement that is separate from your switch.



Also.... this bit doesn't make sense either:

(CHILDREN_MALE*.10);

This effectively does nothing. You are multiplying two numbers, but you don't capture the result so it just gets thrown away. If you are trying to calculate the cost, you will need to assign this to some kind of variable.

Looking at your code, you seem to have an 'Mcost' variable that you don't really use. Perhaps you meant to assign the result to that. This would make much more sense:

Mcost = (CHILDREN_MALE*.10);
So am I supposed to do something like this?

1
2
3
4
5
6
if (Age > 1 && Age < 12)
{
   switch (Age)
   { 
       case 'm': case 'M': 


Also how do I make the CHILDREN_MALE * (.10) if that is the case?
I am kind of confused on what to do, I'm a beginner sorry.
1
2
3
   switch (Age)
   { 
       case 'm': case 'M': 


Is their Age going to be 'm' or 'M'?
Last edited on
No if their Age is less than 12 and greater than 1
I thought that we can put the switch statement inside the if
No if their Age is less than 12 and greater than 1


Yes, that is what your if statement does. But your switch doesn't make any sense.
if (Age > 1 && Age < 12)
{
switch (Age)
{
case 'm': // right here how do I multiply CHILDREN_MALE, which is 50.00 with .10 ?
case 'f': // CHILDREN_FEMALE, 55.00 * .10 ?
}
Last edited on
1
2
3
switch (Age)
{
case 'm':


Again... this doesn't make sense. You're examining the person's Age and checking to see if it is 'm'. 'm' is not an age.

right here how do I multiply CHILDREN_MALE, which is 50.00 with .10 ?


You can mulitply with the * operator:

 
CHILDREN_MALE * .10


This will multiply the two values together. BUT you will be throwing the result away unless you assign it to something:

 
somevar = CHILDREN_MALE * .10;


With this, 'somevar' will now contain the result of the multiplication.
Sorry, I thought I was supposed to examine their age to see if they are are a male or a female for that age group and then decide the price? Also didn't I assign the Mcost = 0.0 and CHILDREN_MALE to 50.00 ?
Ok so if I use somevar=.... and I declare somevar I won't need to use case or do I still need it? Also, I have to use switch statement in the program.
Sorry, I thought I was supposed to examine their age to see if they are are a male or a female


Their age is how old they are... like 12, 18, 32.

Whether or not they are male/female is not their age, but is their gender.

Also didn't I assign the Mcost = 0.0 and CHILDREN_MALE to 50.00 ?


Yes. Mcost is 0, and CHILDREN_MALE is 50.

So if they are under the age of 13 and if they are male, you want to multiply CHILDREN_MALE by 0.10 to get the amount of tax, right?

CHILDREN_MALE * 0.10; will do just that: it is an expression that multiplies those values together. However, unless you do something with the expression (like assign it to a var), the result of the multiplication is lost.

somevar = CHILDREN_MALE * 0.10; will multiply CHILDREN_MALE by 0.10, and will store the result of that multiplication inside of 'somevar'. So after this line of code is executed, somevar will be 5.00
Ya, I need to add that tax onto the actual price of Male so it would be 55 if the male is
(Age 1-12).
So you probably don't want to multiply by 0.10 then.

50 * 0.10 = 5

50 * ? = 55
so I do that for each one right and name it differently something like this:
somevar = 0.0;
somevar = CHILDREN_MALE * 0.10;
somevar_1 = CHILDREN_FEMALE * 0.10
So the tax has to be included in it like this:

I need 3 outputs like this:

1
2
3
4
5
6
7
8
9
10
11
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)
Last edited on
Pages: 123