2014-11-22 3 views
0

메인을 가능한 한 간단하게 유지하려하지만 작동하지 못했습니다. 코드에는 main에 switch 문이 있지만 별도의 함수에 넣기 위해 switch 문에 각 case가 필요합니다. 도와주세요!그룹 프로젝트 극장 좌석 스위치 설명

choice = menu();

switch(choice) 

    { 

    case 1: 

     cout <<"Seating Prices\n\n"; 

     for(int count=0;count<ROWS; count++) 

     { 

      cout <<"The price for row " << (count+1) <<": $"; 

      cout <<price[count] <<endl; 

      getch(); 

     } 

     break; 

    case 2: 

     cout <<"Purchase Tickets\n\n"; 

     do 

     { 

      cout <<"Please enter the row: "; 

      cin >>rowChoice; 

      cout <<"Please enter the seat: "; 

      cin >>seatChoice; 

      if(seating[rowChoice][seatChoice] == '*') 

      { 

       cout <<"That seat is unavailable please make another selection.\n"; 

      } 

      else 

      { 

       cost = price[rowChoice] + 0; 

       total += cost; 

       cout <<"Ticket price: " <<cost <<endl; 

       cout <<"Please confirm your purchase. Enter 1 for yes, 2 for no."; 

       cin >>confirm; 

       if(confirm==1) 

       { 

        cout <<"Your ticket purchase has been confirmed.\n"; 

         seating[rowChoice][seatChoice] = TAKEN; 

         ticketSales++; 

       } 

       else if (confirm==2) 

       { 

        cout <<"Would you like to purchase another ticket? Enter 1 for yes, 2 for no." <<endl; 

        cin >>quit; 

       } 

       cout <<"Would you like to purchase another ticket? Enter 1 for yes, 2 for no."; 

       cin >>quit; 

      } 

     } 

     while (quit==1); 

     break; 



    case 3: 

     int viewRow; 

     cout <<"View Seats by Row\n\n"; 

     cout <<"Enter the row you would like to view"; 

     cin >>viewRow; 

     seatingChartRow(viewRow); 

     cout <<"Press 1 to return to the main menu."; 

     cin >>quit; 

     break; 


    case 4: 

     cout <<"Sales Statistics\n\n"; 
     saleStats(); 

      break; 

    case 5: 

     cout <<"Quit\n"; 

     break; 

    default: cout <<"Error Input\n"; 

    } 

} 
+1

"제대로 작동하지 않을 수 있음"은 적절한 문제 보고서가 아닙니다. 너는 무엇을 기대 했는가? 뭐하고 있니? – Rook

+0

메인에서 switch 문을 사용할 때 정상적으로 작동했습니다. 그러나 작동하지 않을 경우 별도의 기능에 넣습니다. 나는 함수를 잘못 호출하고 다른 함수 정의를 엉망으로 만들지는 모르겠다. –

답변

1

그냥이 수행

choice = menu(); 
switch(choice) 
{ 
case 1: 
    seating(); 
    break; 
case 2: 
    buy_tickets(); 
    break; 
case 3: 
    view_seats(); 
    break; 
case 4: 
    saleStats(); 
    break; 
case 5: 
    cout <<"Quit\n"; 
    break; 
default: cout <<"Error Input\n"; 
} 

을 그리고 필요한 기능에 CIN/cout을 물건을한다.

당신도 판매용으로 이것을 했으므로 그 혼란이 무엇인지 모르십니까?