User controlled loop not working

So I am developing a program that asks the user if he/she wants to buy tickets to a concert. If the user types "B" the program asks the user to enter how many tickets they want and outputs a price. This process should loop until the user enters "F" instead of "B". This seems so simple but I can not figure it out for the life of me.

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

using namespace std;

//struct definition
struct concertpromoter
{
    string concertName;
    double ticketprice;
    int capacity;
    int remainingtickets;
};

int main()
{
    char cont;
    int ticketamt;

    concertpromoter concert;
    concert.capacity = 100;
    concert.ticketprice = 10;
    concert.remainingtickets = 100;

    cout << "-----------------------------------------" << endl;
    cout << " ODU Conservatory Promoter Sales Program " << endl;
    cout << "-----------------------------------------" << endl << endl;

    while (cont = 'B')
    {
        cout << "Enter B to buy tickets" << endl;
        cout << "Enter F to finish buying" << endl;
        cin >> cont;

        if (cont = 'F')
        {
            break;
        }

        cout << "How many tickets to buy? (Maximum 100)" << endl;
        cin >> ticketamt;

        if (ticketamt > concert.remainingtickets)
        {
            cout << "Sorry. We can not process this transaction." << endl;
        }
        else
        {
            cout << "The cost per ticket is $10" << endl;
            cout << "The total cost is $" << ticketamt * 10 << endl;
            concert.remainingtickets = concert.remainingtickets - ticketamt;
            cout << "Tickets remaining: " << concert.remainingtickets << endl;
            cout << "-----------------------------------------" << endl;
        }

    }

        cout << "Tickets remaining: " << concert.remainingtickets << endl;


    return 0;
}
Remember that you need to use == to compare things. A single equals is for assignment.
look at what dutch says then look at lines 30 & 36.
Also look where you created cont what does it equal when you try to run the first pass of the loop. Hint: it's undefined.
Last edited on
Topic archived. No new replies allowed.