|
|
$ g++ -Wall foo.cpp foo.cpp:72:14: warning: multi-character character constant [-Wmultichar] if (s[0] > '13' || s[0] < '1' || s[1] > 'D' || s[1] < 'A') { ^ |
|
|
PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code. Along with the proper indenting it makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/ http://www.cplusplus.com/articles/z13hAqkS/ Hint: You can edit your post, highlight your code and press the <> formatting button. This will not automatically indent your code. That part is up to you. You can use the preview button at the bottom to see how it looks. I found the second link to be the most help. |
arr[i][0] = i + 1 + '0';
works fine for the numbers 0 - 9, or ASCII decimal characters 48 - 57. The problem is when "i" == 9 you have 9 + 1 + 48 = 58 or the ASCII character ":" because you can not store 10 in a single byte. It is possible to store the characters (:, ; and <) and later change these characters into the numbers that you need when you output to the screen.
|
|
airline sit reservation with C++ implantation |
maulk wrote: |
---|
Hello, I cant figure out why my code will only display up to number 9 and not 13 #include <iostream> #include <string> using namespace std; int main() { char arr[13][5]; for (int i = 0; i < 13; i++) { arr[i][0] = i + 1 + '0'; for (int j = 1; j < 5; j++) { arr[i][j] = 'A' + j - 1; } } cout << "initial seat arrangements........\n"; display(arr); airline(arr); return 0; } int seatsFull(char arr[13][5]) { int count = 0; for (int i = 0; i < 13; i++) { for (int j = 1; j < 5; j++) if (arr[i][j] == 'X') count++; } if (count == 28) { return 1; } return 0; } void display(char arr[13][5]) { for (int i = 0; i < 13; i++) { for (int j = 0; j < 5; j++) { cout << arr[i][j] << " "; } cout << endl; } return; } string getData() { string p; cout << "Where would you like to sit? "; cin >> p; return p; } void update(char arr[13][5], int row, int col) { cout << "congrats, your seat is valid. Reserved for you\n"; cout << "updated seat status..........\n"; arr[row][col] = 'X'; } int check(char arr[13][5], string s) { if (s[0] > '13' || s[0] < '1' || s[1]>'D' || s[1] < 'A') { cout << "invalid seat no\n"; return 0; } int row = -1, col = -1; for (int i = 0; i < 13; i++) { if (arr[i][0] == s[0]) row = i; } for (int j = 0; j < 5; j++) { if (arr[row][j] == s[1]) col = j; } if (col == -1) { cout << "Seat is already occupied\n"; return 0; } else { update(arr, row, col); } return 1; } void airline(char arr[13][5]) { cout << "enter Q if you are done!\n"; string s; while (true) { s = getData(); if (s[0] == 'Q') break; if (check(arr, s)) display(arr); if (seatsFull(arr)) { cout << "Sorry plane is full...please try again later" << endl; break; } } cout << "Goodbye.." << endl; } |