Program stuck in a while loop given the input XXn

Hiya everyone, I'm new to this site and I really like it here.
I just started programming and for the first time I'm running up a wall (yikes)
What is happening with my code is that in the NumberChecker function is shitting it self.
But little brief in:
I'm writing a program for airline seating which in it's essence is about double sided arrays. And it's been all fine and dandy until I input XXn into the program.
There it just goes in and gets stuck in a foreverever loop. (And I don't want that)
People have been telling me to do if sentences to check for it, but I've tried, oh how I've tried.
But here's my code and please explain to me how to do it, I've had people explain it to me, but I just can't seem to put my finger on it! So please help me.
Thank you.
Here's the 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <iostream>
#include<cctype>
#include <ctype.h>
#include <iomanip>
using namespace std;
void ArrayMaking(char PlaneSeat[7][4])
{
    for (int i = 0 ; i < 7 ; i++ )
        for (int j = 0 ; j < 4 ; j++)
            PlaneSeat[i] [j] = 'A' + j;

}
void print(char PlaneSeat[7][4])
{


    for (int i = 0 ; i < 7; i++)
    {
        cout  <<  i + 1 << ' ' << " ";

        for (int j = 0 ;  j< 4; j++)
        {
            if (j == 2 )
            {
                cout << " ";
            }
            cout << " " <<  PlaneSeat[i][j] ;
        }
        cout << endl;
    }
    cout << "Seat number:";
}
char AlphabetChecker(char c)
{


    do
    {
        cin.get(c);

        c =  toupper(c);
    }
    while (!isalpha(c));


    return c;
}

char NumberChecker (char n)
{
do
{

cin.get(n);

}
while(!isdigit(n));
return n;
}



void UltimateChecker(char c, char n,char PlaneSeat[7][4])
{


    int sheet;
    int ro;
    if (c >= 65 && c <=68)
    {
        sheet = c - 'A';
    }

    else
    {
        cout << "***Error in input. Please make another request. *** " << endl;
        return;
    }
    ro = n - '1';
    if (0 > ro && ro >= 7)
    {
        cout << "***Error in input. Please make another request. *** "<< endl;
        return;

    }
    if (PlaneSeat[ro][sheet] == 'X')
    {
        cout <<"***The seat is taken. Please make another request. *** "<< endl;
    }
    else
        PlaneSeat[ro][sheet] = 'X';

}










int main()

{
    char c;
    char n;
    char Y_N;
    char PlaneSeat[7][4];
    ArrayMaking(PlaneSeat);

    do
    {
        print(PlaneSeat);
        n=NumberChecker(n);


        c=AlphabetChecker(c);
        UltimateChecker(c,n,PlaneSeat);
        print(PlaneSeat);
        cout << endl;
        cout <<"More seats?" ;
        cin >> Y_N;
    }
    while (Y_N=='Y'||Y_N=='y');
    cout <<endl;
    return 0;

}

Is my code unreadable? If it is do tell, I wish to improve on all factors when it comes to my programming.
Last edited on
bump anyone?
How do you know it's number checker that's broken? Your main() function is exercising every single function you've written. Also, what input are you providing that makes it misbehave? Why are you passing a parameter to that function at all, since you read standard input over it anyway?
#include <iostream>
#include<cctype>
#include <ctype.h>
#include <iomanip>
#include <stdlib.h>
using namespace std;
void ArrayMaking(char PlaneSeat[7][4])
{
for (int i = 0 ; i < 7 ; i++ )
for (int j = 0 ; j < 4 ; j++)
PlaneSeat[i] [j] = 'A' + j;

}
void print(char PlaneSeat[7][4])
{


for (int i = 0 ; i < 7; i++)
{
cout << i + 1 << ' ' << " ";

for (int j = 0 ; j< 4; j++)
{
if (j == 2 )
{
cout << " ";
}
cout << " " << PlaneSeat[i][j] ;
}
cout <<endl;
}
cout << "Seat number:";
}
void getInput(char *c){

while(1){
c[0] = cin.get();
c[1] = cin.get();
cin.ignore(100000, '\n');
if(isdigit(c[0]) && isalpha(c[1])){
c[1] = toupper(c[1]);

return;
}


}
}





void UltimateChecker(char c, char n,char PlaneSeat[7][4])
{


int sheet;
int ro;
if (c >= 65 && c <=68)
{
sheet = c - 'A';
}

else
{
cout << "***Error in input. Please make another request. *** " << endl;
return;
}
ro = n - '1';
if (0 > ro && ro >= 7)
{
cout << "***Error in input. Please make another request. *** "<< endl;
return;

}

if (PlaneSeat[ro][sheet] == 'X')
{
cout <<"***The seat is taken. Please make another request. *** "<< endl;
}
else
PlaneSeat[ro][sheet] = 'X';

}










int main()


{
char c[3];
char Y_N;
char PlaneSeat[7][4];
ArrayMaking(PlaneSeat);


while(1)
{
print(PlaneSeat);
getInput (c);
UltimateChecker(c[1],c[0],PlaneSeat);
print(PlaneSeat);
cout <<"More seats?" ;
cin >> Y_N;
if(!Y_N)
{
break;
}

}


return 0;

}



OK The code has been fixed a lot, but there is now a new problem.
It will read in the input the first time, but everything after that the user has to do the input twice. *Fixed
Last edited on
Topic archived. No new replies allowed.