| | |
code
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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.
I'm here to prove you wrong.
![]() |
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
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete deploy desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline graph homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






