User integer and character Validation

Okay so now every time I run my program i try to check to see if i enter the same seat twice it displays the message but doesn't count it towards the overall sales and also when i key in seat 1a it still takes it as though i already inputted the seat character as well here is my code

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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
      #include<iostream>
#include<string>
#include <iomanip>
using namespace std;

#include "C:\Users\barta\OneDrive\Documents\Visual Studio 2015\Projects\Project 4\Project 4\array.h"

void displayPlane(char msg[], char[ROW][COL]);
void getData(int &, char &);
void salesReport(int classCtr[], double fare[], string classes[]);

int main()
{
    int row = 0;
    int total = 0;
    char seat;


    while (row != -1)
    {

        displayPlane("\tChesapeaake Airlines", layout);
        cout << endl;
        getData(row, seat);
        if (row == -1)
            break;
        cout << endl;
        int COL = seat - 'A';
        if (layout[row - 1][COL] == 'X')
        {

            cout << "Sorry this seat is taken" << endl;
        }
        else
        {

            layout[row - 1][COL] = 'X';
            std::cout << std::fixed;
            std::cout << std::setprecision(2);

            for (int i = 0; i < 3; i++)
            {
                total += classCtr[i];
            }
        }

    }
    double percentOccupied;


    cout << setw(18) << "Total Seats =  " << total << endl << endl;
    percentOccupied = ((double)total / 36) * 100;
    cout << setw(22) << "Percent Occupied = " << percentOccupied << endl;
    cout << endl;
    salesReport(classCtr, fare, classes);
    cout << endl << endl;

    cout << "Have a nice day! " << endl;

    system("pause");
    return 0;
}
void displayPlane(char msg[], char[ROW][COL])
{
    cout << msg << endl;
    for (int r = 0; r < ROW; r++)
    {
        cout << endl;
        cout << setw(4) << r + 1;
        for (int c = 0; c < COL; c++)
        {
            cout << setw(4) << layout[r][c];
        }

    }

}
void getData(int& row, char& seat)
{
    cout << "Enter row <-1 to stop>  ";
    cin >> row;
    cout << endl;
    if (row == -1)
        return;
    if (row == 1)
    {
        classCtr[0]++;
    }
    else if (row >= 2 && row <= 4)
    {
        classCtr[1]++;
    }
    else if (row >= 5 && row <= 9)
    {
        classCtr[2]++;
    }

    cout << "Enter your prefered seat  ";
    cin >> seat;
    seat = toupper(seat);


}
void salesReport(int classCtr[], double fare[], string classes[])
{
    double totalSales = 0;
    for (int i = 0; i < 3; i++)
    {
        totalSales += classCtr[i] * fare[i];
    }
    cout << setw(34) << "Sales Report\n\n" << setw(23) << "Ticket Price" << setw(16) << "Total Sales\n\n"
        << setw(14) << classes[0] << "\t" << fare[0] << setw(6) << classCtr[0] << setw(9) << fare[0] * classCtr[0] << "\n\n"
        << classes[1] << "\t" << fare[1] << setw(6) << classCtr[1] << setw(9) << fare[1] * classCtr[1] << "\n\n"
        << setw(14) << classes[2] << "\t" << fare[2] << setw(6) << classCtr[2] << setw(9) << fare[2] * classCtr[2]
        << "\t\n\n Total Sales = " << totalSales;
}



here is the header file
[/code]
/arrays for airline problem

const int ROW = 9;
const int COL = 4;
const int CTR = 3;

//initial seats in the plane
char layout[ROW][COL] = { { 'A', 'B', 'C', 'D' },
{ 'A', 'B', 'C', 'D' },
{ 'A', 'B', 'C', 'D' },
{ 'A', 'B', 'C', 'D' },
{ 'A', 'B', 'C', 'D' },
{ 'A', 'B', 'C', 'D' },
{ 'A', 'B', 'C', 'D' },
{ 'A', 'B', 'C', 'D' },
{ 'A', 'B', 'C', 'D' }};

int classCtr[CTR] = {0,0,0};

string classes[] = {"First Class", "Business Class", "Coach"};

double fare [] = {500, 300, 100};
[/code]

here is the out put i am getting

Chesapeaake Airlines

1 A B C D
2 A B C D
3 A B C D
4 A B C D
5 A B C D
6 A B C D
7 A B C D
8 A B C D
9 A B C D
Enter row <-1 to stop> 1a <------- right here you can see it tooke both inputs at the same time

Enter your prefered seat
Chesapeaake Airlines

1 X B C D
2 A B C D
3 A B C D
4 A B C D
5 A B C D
6 A B C D
7 A B C D
8 A B C D
9 A B C D
Enter row <-1 to stop> 1a

Enter your prefered seat
Sorry this seat is taken
Chesapeaake Airlines

1 X B C D
2 A B C D
3 A B C D
4 A B C D
5 A B C D
6 A B C D
7 A B C D
8 A B C D
9 A B C D
Enter row <-1 to stop> 2

Enter your prefered seat d

Chesapeaake Airlines

1 X B C D
2 A B C X
3 A B C D
4 A B C D
5 A B C D
6 A B C D
7 A B C D
8 A B C D
9 A B C D
Enter row <-1 to stop> 2

Enter your prefered seat d

Sorry this seat is taken
Chesapeaake Airlines

1 X B C D
2 A B C X
3 A B C D
4 A B C D
5 A B C D
6 A B C D
7 A B C D
8 A B C D
9 A B C D
Enter row <-1 to stop> 2

Enter your prefered seat d

Sorry this seat is taken
Chesapeaake Airlines

1 X B C D
2 A B C X
3 A B C D
4 A B C D
5 A B C D
6 A B C D
7 A B C D
8 A B C D
9 A B C D
Enter row <-1 to stop> -1

Total Seats = 4

Percent Occupied = 11.11

Sales Report

Ticket Price Total Sales

First Class 500.00 2 1000.00 <-----Right here you see it was counted

Business Class 300.00 3 900.00 <------ And you see the same when I typed in 2 D 3 times

Coach 100.00 0 0.00

Total Sales = 1900.00

Have a nice day!
Press any key to continue . . .
Last edited on
Hello,

you call getData to receive the row. Then you change classCtr in that function. After the function returns you check whether the seat is already taken.
The next time a valid seat is entered you sum up these "invalid" changes.

Regards,
mathes
Topic archived. No new replies allowed.