Like Tree2Likes
  • 2 Post By iMalc

Help in 1D C++

This is a discussion on Help in 1D C++ within the C++ Programming forums, part of the General Programming Boards category; Help !!!!...

  1. #1
    "PALINDROME"
    Join Date
    Nov 2010
    Posts
    59

    Help in 1D C++

    Help !!!!
    Last edited by [Student]; 07-16-2011 at 09:59 PM.

  2. #2
    "PALINDROME"
    Join Date
    Nov 2010
    Posts
    59
    Code:
    #include<iostream>
    #include<conio.h>
    using namespace std;
    
    void waitinglist(int choice, int plane[11]){
        
        cout<<"First Class"<<endl;
        cout<<" ---------------------\n";
        cout<<"   ";
        for(int i=1; i<=5; i++){
        if(choice == plane[i]){
                  cout<<"X   ";
                  }  
                  }
                  }
    void waitinglist2(int choice, int plane[11]){
         
          cout<<"\n\nEconomy"<<endl;
        cout<<" ---------------------\n";
        cout<<"   ";
        for(int i=1; i<=5; i++){
                if(plane[i] == choice){
                cout<<"X   ";
                  }  
                  }
                  }
         
    int main(){
        
        int plane[11]={0};
        int i = 0;
        int firstclass=1;
        int economy = 6;
        int choice;
        char response[2];
        
        
        press:
              waitinglist(choice,plane);
              waitinglist2(choice,plane);
        cout<<"\n\n\nPlease type 1 - First class \n";
        cout<<"Please type 2 - Economy \n";
          
        while ( i < 10 ) {
           cin>>choice;
           if(choice == 1){
                     if(!plane[firstclass] && firstclass<=5){
                     cout<<"\nReservation Confirmed - Seat# "<<firstclass<<"\n";;
                     plane[firstclass++]=1;
                     i++;
                     getch();
                     system("cls");
                     goto press;
                     }
                     
                     else if ( firstclass > 5 && economy <= 10 ) {
                     cout<<"\nThe first class section is full.\n";
                     cout<<"Would you like to sit in the economy";
                     cout<<" section ( Y or N )? ";
                     cin>>response;
                     
                     if ( response[ 0 ] == 'Y') {
                          cout<<"\nReservation Confirmed - Seat# "<<economy<<"\n";
                          plane[ economy++ ] = 1;
                          i++;
                          getch();
                          system("cls");
                          return main();
                          }
                          else { 
                          cout<<"\nNext flight leaves in 3 hours.\n";
                          getch();
                          system("cls");
                          goto press;
                          } 
                          } 
                          else { 
                          cout<<"\nNext flight leaves in 3 hours.\n";
                          getch();
                          system("cls");
                          return main();
                          }
    
                          } 
                          else { 
                               if ( !plane[ economy ] && economy <= 10 ) {
                               cout<<"\nReservation Confirmed - Seat# "<<economy<<"\n";
                                plane[ economy++ ] = 1;
                                i++;
                                getch();
                                system("cls");
                                goto press;
                                }
                                else if ( economy > 10 && firstclass <= 5 ) {
                                 cout<<"\nThe first class section is full.\n";
                                 cout<<"Would you like to sit in the economy";
                                 cout<<" section ( Y or N )? ";
                                 cin>>response;    
                                 
                                 if ( toupper( response[ 0 ] ) == 'Y' ) {
                                      cout<<"\nReservation Confirmed - Seat# "<<firstclass<<"\n";
                                      plane[ firstclass++ ] = 1;
                                      i++;
                                      getch();
                                      system("cls");
                                      goto press;
                                      }
                                      else {
                                           cout<<"\nNext flight leaves in 3 hours.\n";
                                           getch();
                                           system("cls");
                                           return main();
                                           }
                                           }
                                           else { 
                                           cout<<"\nNext flight leaves in 3 hours.\n";
                                           getch();
                                           system("cls");
                                           return main();
                                           }
                                           }
                                           }
                                           cout<<"\nReservation Full\n"; 
                                           getch();
                                           system("cls");
                                           return main();               
                                           return 0;
                                           }
    Here is My Code I'm at average of 85%, I'm Stuck in Waiting List....plz need your help!...

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    What, exactly, are you stuck on?

  4. #4
    "PALINDROME"
    Join Date
    Nov 2010
    Posts
    59
    I'm Stuck in this code....i got a wrong in waiting list....plz i need your help...

    Code:
    void waitinglist(int choice, int plane[11]){
        
        cout<<"First Class"<<endl;
        cout<<" ---------------------\n";
        cout<<"   ";
        for(int i=1; i<=5; i++){
        if(choice == plane[i]){
                  cout<<"X   ";
                  }  
                  }
                  }
    void waitinglist2(int choice, int plane[11]){
         
          cout<<"\n\nEconomy"<<endl;
        cout<<" ---------------------\n";
        cout<<"   ";
        for(int i=1; i<=5; i++){
                if(plane[i] == choice){
                cout<<"X   ";
                  }  
                  }
                  }

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Your code prints some number of X's. Is it supposed to do something else?

    Also, note that the first time you call this function, the value of choice is indeterminate.

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    I can help you alright...

    1. Stop calling main() recursively!
    2. Stop using goto!
    3. Fix your code indentation. Writing code is not supposed to be a curly-brace counting exercise!

    Yes I'm totally serious.
    stahta01 and Salem like this.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21