MiniProject #2, Questions.

Greetings, im new to this site and still new to coding. Im having trouble with this project.
b. A loop should be used to iterate once for each ticket. In each iteration, the loop should ask the user:

the desired location in the concert location for a ticket; a letter (either section F (for floor), A, B, C, or L (for lawn). Note accept both upper and lowercase letters - If an incorrect location is entered keep asking for the user to re-enter till a correct letter is entered.
then ask the user the row location; each section has rows 1 - 50 (except for the lawn - which is standing room only and no assigned seating); use the chart below to assign a price to a ticket
if they are a member of the artist's fan club discount the ticket by 10%
Display the number of tickets in each section, the subtotal for the tickets in each section, and the grand total for all tickets purchased by the user (you do not need an array - as we have not covered them yet - just use variables)..


I think i got a good part of it down, however i need help with assigning the correct value to the tickets, and coming up with the total value/displaying the values. I honestly just dont understand how to go about doing it, i know a count variable is involved i just cant wrap my head around exactly how to do that. I hope you guys can help out a bit, and i really do appreciate you guys taking time out of your lives to help people. When im actually good at coding ill try my best to help others too.

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
  #include <iostream>

using namespace std;

int main()
{
	int tickets = 0;
	int numOfTickets = 0; 

	int row = 0;
	char letters;
	bool choice;
	bool choice2;
	int club = 0;
	int i = 0;



	cout << "How many tickets do you need?" << endl;
	cin >> tickets;

	if (tickets < 1 || tickets > 25)
	{
		cout << "You have entered an invalid ammount of tikets! Pleas enter an amount within the range of 1-25." << endl;
		cin >> tickets;
		
		
	}
	for (int i = 0; i < tickets; i++)
	{
		do
		{
			cout << "What is your desired location for each ticket? A,a B,b C,c L,l(lawn) F,f(floor) " << endl;
			cin >> letters;
			if (letters == 'A' || 'a' || 'B' || 'b' || 'C' || 'c' || 'L' || 'l' || 'F' || 'f')
			{
				cout << "Please enter which row you would like to be in" << endl;
				cin >> row;
				while (row < 1 || row >50);
				{
					cout << "Error please enter a number between 1 and 50";
				}
				choice = false;
			}
			else
			{
				cout << "Sorry you have entered an incorrect location, please enter a valid location" << endl;
				choice = true;
			}

		} while (choice == true);
	}
	do
	{
		cout << "Are you a member of the artist's fan club? Enter 1 for yes, and 0 for no." << endl;
		cin >> club;
		if (club == 1 || 2)
		{
			choice2 = false;
		}
		else
		{
			
			cout << "you have entered and invalid response!" << endl;
			choice2 = true;
		}

	} while (choice2 == true);
	
	
	return 0;

}
What you did on lines 35 and 57 is a common beginners mistake:

if (letters == 'A' || 'a' || 'B' || 'b' || 'C' || 'c' || 'L' || 'l' || 'F' || 'f')

if (club == 1 || 2)

These two lines aren't doing what you think they're doing. Computers don't make assumptions and understand intentions the way humans do - you have to be explicit, and write out each condition like so:

if(letters == 'A' || letters == 'a' || letters == 'B' /*and so on...*/)

As it stands, the expressions will always evaluate to true, because
2
on line 57 and
'a', 'B', 'b', 'C', 'c', 'L', 'l', 'F', 'f'
on line 35 are all nonzero when interpreted as integers (which, interpreted as a boolean, is true).

In addition, you can effectively cut your conditions in half on line 35 with the use of std::toupper or std::tolower found int <cctype>.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <cctype>
#include <iostream>

int main() {
	char character = 'a';

	character = std::toupper(character);

	if (character == 'A' || character == 'B') {
		std::cout << "The condition has been met." << std::endl;
	}

	return 0;
}
Last edited on
OK, Awesome thank you so much, i changed my if statement, and im not sure if we are allowed to use the to upper or to lower function. Do you know what i should do for the count variable? how do i make a variable that tracks the price of each ticket through out the function?
@Dantecode, how do you want to get the ticket price?
1. Do you want the user to enter the ticket price?
2. or do you have a set price based on which section they're being seated in.

3. If working with ticket price I would declare and initialize it first.
double TicketPrice = 0;
i need to get the ticket price based on constant prices, here is what i have, sorry for all the code. section a row 1 to 25 will always be 175, 1-50 will be 145, and so on
#include <iostream>

using namespace std;

int main()
{
int tickets = 0;
int numOfTickets = 0;
int row = 0;
char letters;
bool choice;
bool choice2;
int club = 0;
int i = 0;
int count = 0;
double subTotalA = 0;
double subTotala = 0;
double subTotalB = 0;
double subTotalb = 0;
double subTotalC = 0;
double subTotalc = 0;
double subTotalF = 0;
double subTotalf = 0;
double subTotalL = 0;
double total = 0;

cout << "How many tickets do you need?" << endl;
cin >> tickets;

if (tickets < 1 || tickets > 25)
{
cout << "You have entered an invalid ammount of tikets! Pleas enter an amount within the range of 1-25." << endl;
cin >> tickets;


}
for (int i = 0; i < tickets; i++)
{
do
{
cout << "What is your desired location for each ticket? A,a B,b C,c L,l(lawn) F,f(floor) " << endl;
cin >> letters;
if (letters == 'A' || letters== 'a' || letters == 'B' || letters == 'b' || letters =='C' || letters== 'c' || letters == 'L' || letters == 'l' || letters == 'F' || letters =='f')
{
count++;
cout << "Please enter which row you would like to be in" << endl;
cin >> row;
while (row < 1 || row > 50);
{
cout << "Enter again please" << endl;
}

choice = false;
}
else
{
cout << "Sorry you have entered an incorrect location, please enter a valid location" << endl;
choice = true;
}

} while (choice == true);
if (letters == 'A' || letters == 'a' && row >= 1 || row <= 25)
{
subTotalA = 175;
}
if (letters == 'A' || letters == 'a' && row >= 26 || row <= 50)
{
subTotala = 145;
}
if (letters == 'B' || letters == 'b' && row >= 1 || row <= 25)
{
subTotalB = 125;
}
if (letters == 'B' || letters == 'b' && row >= 26 || row <= 50)
{
subTotalb = 110;
}
if (letters == 'C' || letters == 'c' && row >= 1 || row <= 25)
{
subTotalC = 90;
}
if (letters == 'C' || letters == 'c' && row >= 26 || row <= 50)
{
subTotalc = 75;
}
if (letters == 'F' || letters == 'f' && row >= 1 || row <= 25)
{
subTotalF = 250;
}
if (letters == 'F' || letters == 'f' && row >= 26 || row <= 50)
{
subTotalf = 225;
}
if (letters == 'L' || letters == 'l' && row >= 1 || row <= 25 && row >= 26 || row <= 50)
{
subTotalL = 0;
}
}
do
{
cout << "Are you a member of the artist's fan club? Enter 1 for yes, and 0 for no." << endl;
cin >> club;
if (club == 1 || club == 0)
{
subTotalA = subTotalA * .10;
subTotala = subTotala * .10;
subTotalB = subTotalB * .10;
subTotalb = subTotalb * .10;
subTotalC = subTotalC * .10;
subTotalc = subTotalc * .10;
subTotalF = subTotalF * .10;
subTotalf = subTotalf * .10;
choice2 = false;
}
else
{

cout << "you have entered and invalid response!" << endl;
choice2 = true;
}

} while (choice2 == true);
total = subTotalA + subTotala + subTotalB + subTotalb + subTotalC + subTotalc + subTotalF + subTotalf + subTotalL;
cout << "The number of tickets you have requested: " << endl;
cout << count << endl;
cout << "the total ammount is: $" << total << endl;



return 0;

}
Last edited on
Also, the user must input which section they want and which row they want, depending on the section and the row, the price will change, based on what their predetermined prices are.
I haven't compiled your code but I do see some syntax errors it seems. I can't point out which lines however because the code you posted isn't in the correct code brackets.

[.code] Code goes here. [./code]

^ discard the dots.
Topic archived. No new replies allowed.