Long day

Hi guys so it's been a long day and I can't vent how angry I am

I love programming and I want to be the best programmer I can be and I have been putting countless hours in but it's things like this that makes me want to throw my laptop against a wall,because I am looking at the logic and I can't see how the logic is incorrect

when I call bookSeat,it just keeps printing seat not found

but how?????????


the seat clearly is found I have a map of seats which are properly sorted and initalised inside a map called seats

so when i = 2 and j = 'B' the if statement SHOULD execute and return true but instead it skips it and says seat not found wtf :s

beyond frustrated

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
  bool bookSeat(int row,char letter){

     for(int i = 1; i < row; i++){

        for(char j = 'A'; j <= letter; j++){

            if(row == seats[Seat(i,j)].number && letter == seats[Seat(i,j)].letter){

                cout << "seat found,do you want to book this seat press one for yes 2 for no" << endl;
                int choice;
                cin >> choice;

                if(choice == 1){

                    seats[Seat(i,j)].taken = true;
                    return true;
                }
            }
        }
      }
        cout << "seat not found " << endl;
        return false;
  }


int main()
{
    Airline Delta("Delta",101);
    Delta.addSeats(50,'F');

    Delta.bookSeat(2,'B');
    Delta.printSeats(50,'F');


}
Last edited on
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
bool bookSeat(int row,char letter,int lastRow,int lastLetter){

     for(int i = 1; i < lastRow; i++){

        for(char j = 'A'; j <= lastLetter; j++){

            if(seats[Seat(i,j)].number == row && seats[Seat(i,j)].letter == letter){

                cout << "seat found,do you want to book this seat press one for yes 2 for no" << endl;
                int choice;
                cin >> choice;

                if(choice == 1){

                    seats[Seat(i,j)].taken = true;
                    return true;
                }
            }
        }
      }
        cout << "seat not found " << endl;
        return false;
  }
};

int main()
{
    Airline Delta("Delta",101);
    Delta.addSeats(50,'F');

    Delta.bookSeat(2,'B',50,'F');
    Delta.printSeats(50,'F');


}



Sorry I am not thinking straight have not eaten in hours and I realised that I should have used the size of the rows and last letter because the loop only went as far as 2 and letter B

Anyway I'm sorry for so many posts,these small things really drive me crazy sometimes

but thanks for sticking with me you guys on here mean a lot to me and have helped me so much.

I just find that I'm progressing so slowly =(,even though I put a lot of time into it between reading books,buying courses,browsing forums,and ofcourse writing small programs
Topic archived. No new replies allowed.