Mid Project pt 2.

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)..



Okay so i am new to C++ and i am a little overwhelmed and i know i have to use a if statement but i am not sure which one. This was for the first part of the code and now i am on the second part and have to build off that code i already typed which is part 1


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  #include <iostream>
using namespace std;

int main()
{
	int tickets = 0;

	cout << "How Many Tickets Do You Want?" << endl;
	cin >> tickets;

	if (tickets < 1 || tickets > 25)
	{


		cout << " You have entered an invalid ticket number, please enter between 1-25" << endl;
		cin >> tickets;
	}

	system("pause");
	return 0;
}
Last edited on
We can't just help you with your homework before you have even tried. You need to use loops as well as if statements. Research on how to use loops, look up info on google and on youtube, try stuff yourself. Come back later and show us what you tried, and how it worked out. And it's much easier to help if you have a specific question.
A loop should be used to iterate once for each ticket.

Some questions to think about:

Which loop would you like to use a while loop, do-while loop, or a for loop?
HINT: Use the loop that you learn at your class

What part of the loops are you having issues with?

What have you worked so far on your project?

The code you posted here is the same that a person who helped you posted here:

http://www.cplusplus.com/forum/beginner/175562/

You need to read about loops. We all been there. Once you show your work, we could help.

Last edited on
@TarikNeaj , you beat me to it :)
i don't expect you guys to just do my homework for me i actually want to learn this to be a good programmer.. sorry for coming off that way.. but this is was i have so far for


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.




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
   #include <iostream>

using namespace std;

int main()
{
	
	int lawn;
	int floor;
	int a, b, c;

	while (lawn == false)
	{
		cout << "would you like to sit in section a,b,c" << endl
		cin >> a;
		cin >> b;
		cin >> c;
	}
	
	
}
I would break down the problem into smaller parts.

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

Maybe use a do-while loop.

a letter (either section F (for floor), A, B, C, or L (for lawn)

Maybe declare variable that would take the letters or characters.

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.

If you know about the toupper/tolower function, then you can use it.
If you do not know those functions, then maybe you could use a while loop to validate the user data.

then ask the user the row location;

Declare a variable that would take integers to ask the user for the row.

each section has rows 1 - 50 (except for the lawn - which is standing room only and no assigned seating)

Again, use a while loop to validate the user input the row number between 1 and 50.

if they are a member of the artist's fan club discount the ticket by 10%

Key word is if statement

Display the number of tickets in each section

Use a counter (ii.e. count++) to count the number of tickets per section.

the subtotal for the tickets in each section

Use a running total for the specific section.

and the grand total for all tickets purchased by the user

Add the total.

I hope it will give you an idea.



Last edited on
So i switched up my code for the section and row and got this so far







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
 #include <iostream>

using namespace std;

int main()
{
	
	char seat_location = 'x';
	int row = 0;
	char discount = 'a';
	char buffer;




	do
	{
		cout << "would you like to sit in section F,L,A,B,C" << endl;
		cin >> buffer;
	}

		while (seat_location=='x')


		

		
	do
	{
		cout << "Which row would you like to sit in" << endl;
			
		
		}
	
	
	
}



The while loop is especially useful for validating input. If an invalid value is entered, a loop can require that the user reenter it as many times as necessary. For example, the following loop asks for a number in the range of 1 through 100:

1
2
3
4
5
6
7
cout << "Enter a number in the range 1-100: ";
cin >> number;
while (number < 1 || number > 100)
{
cout << "ERROR: Enter a value in the range 1-100: ";
cin >> number;
}


This code first allows the user to enter a number. This takes place just before the loop. If the input is valid, the loop will not execute. If the input is invalid, however, the loop will display an error message and require the user to enter another number. The loop will continue to execute until the user enters a valid number.

The do-while loop is a posttest loop. This means it does not test its expression until it has completed an iteration. As a result, the do-while loop always performs at least one iteration, even if the expression is false to begin with. This differs from the behavior of a while loop, which you will recall is a pretest loop.

The following do-while loop will execute once because the do-while loop does not evaluate the expression x < 0 until the end of the iteration.

1
2
3
4
5
6
int x = 1;
do
{
   cout << x << endl;

}while (x < 0);


The do-while loop is a good choice for repeating a menu.
Last edited on
Hi cjskipwo

Break each requirement down... Then make a function to handle each requirement. This code I'm about to show you is to give you an IDEA... not meant to turn in... I wrote it in about 5 minutes, so it's pretty much crap, may not even compile... but you'll see one way of handling this...

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
#include <iostream>
#include <stdlib.h>
#include <string>

using namespace std;

int amount_of_tickets(int);
string seatlocator (int, string);
int locator(int,int);

int main()
{
    int stubs=0;
    string Seatloc[25];
    string Seats;
    int locator[25];

	stubs = amount_of_tickets (stubs) ;
	cout <<" You have " <<stubs << " tickets." << endl;
     for (int itr=1;itr<25;itr++)
    Seats = seatlocator(itr, Seats);
    Locator = locator(itr2,loc);

	system ("PAUSE");
	return 0;
}

    int amount_of_tickets (int stubs){
    cout << "How Many Tickets Do You Want?" << endl;
	cin >> stubs;
	if (stubs > 0 && stubs < 26)
    { return stubs;}
         else {
	{cout << " You have entered an invalid ticket number, please enter between 1-25" << endl;
	amount_of_tickets (stubs);}
}
}

string seatlocator (int num, string Seats)
{
    cout << "Where would you like to be seated for ticket " << num << "?" << endl;
    cout << "F-loor\nSect A\nSect B\nSect C\nL-awn" << endl;
    return  string variable;
    }

string locator (int itr2, int loc)
{
    cout << "What number seat would you prefer 1-50 ? " << endl;
    return int variable;
    }



Now that you see a concept, run with it. Remember something.

1. A function is written primarily to save you from having to re-use the same coding over and over. Any routine you need more than twice, needs a function written to handle it.

and

2. Some of the greatest functions ever written only do one thing.

I've written code with functions like

void lvlup(){
lvl++;
}

Now that's a great function. :)
Last edited on
Topic archived. No new replies allowed.