| | |
code
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; void intialize(char array[][6]){ for(int i=0;i<13;i++) for(int j=0;j<6;j++) array[i][j]='*'; } void menu (char array [][6]){ cout <<endl; cout<<"\tA\tB\tC\tD\tE\tF"<<endl; for (int i =0; i<13 ;i++){ cout<<"Row "<<i+1<<'\t'; for(int j=0;j<6;j++){ cout<<array[i][j]<<"\t"; } cout<<endl; } cout<<endl; } void main(){ char array[13][6]; intialize(array); char smoking,type,exit,column; int row,col; do{ smoking = 'N'; do{ cout<<"Enter ticket type (F:first class or E:economy class) : "; cin >> type; }while(type !='F' &&type !='f'&&type !='e'&&type !='E'); if(type =='E' || type=='e'){ cout <<"Enter \'S\' for smoking section or \'N\' nonsmoking section : "; cin>> smoking; } menu(array); //do{ cout <<"Enter desired seat ( Row and Column ) : "; cin >>row >> column; while (row <=0 && row>13 || column < 'A' && column < 'F'){ cout<<"Invalid value "<<endl; cout <<"Enter desired seat ( Row and Column ) : "; cin >>row >> column; } while ((type =='F' || type=='f') && row >2){ cout <<"Error! ,only first and second rows is first economy class"<<endl; cout <<"Enter desired seat ( Row and Column ) : "; cin >>row >> column; } while ((smoking=='S' || smoking=='s') && row <8 ){ cout <<"Error! ,this section is nonsmoking"<<endl; cout <<"Enter desired seat ( Row and Column ) : "; cin >>row >> column; } do{ switch (column){ case 'A': col = 0; break; case 'B': col = 1; break; case 'C': col = 2; break; case 'D': col = 3; break; case 'E': col = 4; break; case 'F': col = 5; break; } if (array[row-1][col]=='X'){ cout<<"The seat is occupied "<<endl; cout <<"Enter desired seat ( Row and Column ) : "; cin >>row >> column; } else break; }while(true); cout<<"Your seat is in Row "<<row<<" and in column "<<column<<endl; array[row-1][col]='X'; menu(array); cout<<"Enter E to Exit or enter any key to continue : "; cin >>exit; }while(exit !='E' && exit !='e'); }
there are always hope
>how can I make the last code shorter and more clear .
I'd say it's plenty clear, and the only easy way to make it shorter is to drop the switch statement in favor of something like this:
To nitpickers: yes, I know.
I'd say it's plenty clear, and the only easy way to make it shorter is to drop the switch statement in favor of something like this:
C++ Syntax (Toggle Plain Text)
// Find the display index of the selected column col = column - 'A';
Last edited by Narue; Feb 14th, 2008 at 2:03 pm.
New members chased away this month: 5
![]() |
Similar Threads
- Code 19 Registry Error (Windows NT / 2000 / XP)
- Why won't this code work? (VB.NET)
- Need help with DirectX code (C)
- Tutorials & Code Submissions - Questions? (DaniWeb Community Feedback)
- Some Basic Code Hopefully (Help Needed) (HTML and CSS)
Other Threads in the C++ Forum
- Previous Thread: Math tutor
- Next Thread: Dubbuging
Views: 549 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll dynamic encryption error file forms fstream function functions game givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linker linux loop looping loops map math matrix memory microsoft newbie news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort stream string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






