嵌套if else if语句有多个变量for循环

时间:2014-06-01 03:16:12

标签: vb.net structure

以下是我用于飞机座位选择的程序的代码。它根据吸烟或非吸烟偏好为乘客提供座位。

我正在使用嵌套的if else语句,每个语句中包含2个变量作为计数器和累加器以及嵌套if-then-else语句,这些语句应该填充assign[]结构数组。

我是否无法使用索引的计数器将结构数组直接复制到其他结构数组中?帮助* /

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>

using namespace System;
using namespace std;


struct passengers{
char plname[15] ;//passenger name in array
char pfname[15];
char stPref;// = seat preference, either S smoking or N non-smoking
int row;//row 0-40  (41 rows) index data, to be used later to match the index to the structure of array index
int col; //column 1-3
};struct passengers waiting[41];//Hard Coded Array of struct passengers waiting members for use with output testing
//= {{"WOODS","BILL",'S',10,2},{"BORAX","M T", 'S', 9, 2},{"THOMAS","LINDA",'N',7,2},{"HAYWARD","MARK",'N',7,3},{"SWIFT","TOM",'N',8,1},{"DOBBS","DR.",'N',8,2},{"GOLDEN","VINNIE",'N',8,3},{"HACKER","E",'N',5,3},{"RUSSEL","STEVE",'N',5,1},{"CHAMPION","SPARKY",'N',3,1},{"INNERMENTS","TEX",'S',8,2}};

//Hard Coded Array of struct passengers all[41]. This is a list of all people that want on the plane
struct passengers all[41] = {{"SMITH","JOHN",'N',3,2},{"STEVE","JOBS",'S',9,3},{"CAPONE","AL",'N',3,2},{"JACKSON","MICHAEL",'S',8,1},{"HUMPHREY","H",'S',8,2},{"RINEHART","JIM",'N',3,1},{"EASTMAN","KEN",'N',1,1},{"WINSTON","SALEM",'S',8,3},{"SMYTHE","SUSAN",'S',9,1},{"KENDRIKS","AL",'N',9,2},{"ALLISON","DENNIS",'S',9,3},{"GREENBLATT","RICHARD",'S',10,1},{"DAVIS","BOB",'S',10,3},{"WOODS","BILL",'S',10,2},{"BORAX","M T",'S',9,2},{"HENRY","JOHN",'N',1,2},{"STEVASON","E",'N',1,3},{"WILLIAMS","KEN",'N',2,1},{"SMITH","MARTHA",'N',2,2},{"KOCH","JOE",'N',2,3},{"PACKARD","H P",'N',3,3},{"RINEHART","JANE",'N',3,2},{"SWENSON","CECIL",'N',4,1},{"CORY","TROY",'N',4,2},{"BYES","NICKOLINE",'N',4,3},{"BYES","JENNIFER",'N',5,3},{"HARRIS","JOHN",'N',5,2},{"HARRIS","JUDY",'N',5,1},{"HARTMAN","F G",'N',6,1},{"SOUSE","D T",'N',6,2},{"JOHNSON","MAGIC",'N',6,3},{"LAMPTON","GEORGE",'N',7,1},{"THOMAS","LINDA",'N',7,2},{"HAYWARD","MARK",'N',7,3},{"SWIFT","TOM",'N',8,1},{"DOBBS","DR.",'N',8,2},{"GOLDEN","VINNIE",'N',8,3},{"HACKER","E.",'N',5,3},{"RUSSEL","STEVE.",'N',5,2},{"CHAMPION","SPARKY.",'N',3,1},{"INNERMENTS","TEX.",'S',8,2}}; 

struct passengers assign[30];//Array of structures for the actual seating assignment
//Initializes char array plane so all seats are empty


char plane[10][3] = { {'E','E','E'},{'E','E','E'},{'E','E','E'},{'E','E','E'},{'E','E','E'},{'E','E','E'},{'E','E','E'},{'E','E','E'},{'E','E','E'},{'E','E','E'} };

int x,y,z,a,b,c,count = 0;//Declares integer variables for use with accumulators and counters.

void entList();//Enter function prototype 
void prtList();//Print function prototype
void seatPrgm();//Enters Passengers based on seat availability 
/*******************************************    Main Program    ********************************************************************/
int main()
{
/********** Decision, Selection, Iteration Section... Assigns Seats based on Availability   **********/
while (z<41)
{
    //seatPrgm();


//************************************  User Case Selection Menu    *******************************************/            
char menu = '#';//Declares menu a character variable.This variable will be used for the menu selections and has a default value
    //of # to ensure no problems with it's buffer.

    printf("\t\t\tWelcome to Fast Flights.\n\n\t\tPlease Make a selection from thew menu\n\n");//User Prompt
    printf("\t\tE to Enter Passenger Seating Information\n\t\tP to Print the Assigned Seating Report\n\t\tQ to quit.\n\n");

    scanf("%c",&menu);//scans in the menu selection 

while(menu !='Q')//While variable menu does not equal Q...
        {
        menu =(toupper(menu));
         switch(menu)//Switch Statement generates a case selection menu...
                {

             case 'E' : entList();

                       printf("\n\t\t\n\n");

                       system("pause");

                       scanf("%c",&menu);


                       break;

             case 'P' : prtList();
                       printf("\n\t\t\n\n");
                       system("pause");
                       scanf("%c",&menu);
                       break;

            default  :  if (menu!= 'Q')
                        printf("\n\t\nPlease enter one of the selections\n");
                        else printf("\n");
                        scanf("%c",&menu);
                        system("pause"); 
                        break;
                }
            }
system("pause");//namespace system pause Pauses the program long enough to display data
return 0;//returns null value to int main()
}
}
void entList()
{   /*count=0;
    printf("\tPlease enter passenger name and seating preferences\n");
    printf("\nPassenger Name:");
    gets(assign[count].pname);
    //  scanf("%c");  //  this gets the enter key left over in the buffer  - do not need this after a gets
    printf("\nSeating Preference Smoking or Non-Smoking? Please enter S or N:");        
    scanf("%c",&assign[count].stPref);
    //  it was skipping because I had formatting in the scanf statement
    printf("\nEnter the Seat Row Number:");
    scanf("%c",&assign[count].row);
    printf("\nEnter the Seat Column Number:");
    scanf("%c",&assign[count].col);
    count++;*/
} 

//Print Function Header
void prtList()
{
/************** This section prints the first header for the Non-Smoking Section ***********************/

    printf("\n\n");
    for (x = 0; x<80; x++)
        printf("*");        //Prints the asterisks in the heading
    printf("\n");
    for (x = 0; x<6; x++)
        printf("*");
    printf("\n");
    printf("*\t\t\tNon Smoking Section\n");
    printf("*\n");
    for (x = 0; x<80; x++)
        printf("*");
    for (x = 0; x<6; x++)
        printf("*");
    printf("*\n");
/****************** Prints the Non-Smoking Section Seating Assignments ****************************************/
printf("\n");
        x=0;
for(a=0;a<7;a++)
{
    for(b=0;b<3;b++)   //Prints passengers assign.[30] structure of arrays Non Smoking Section last name and first name members
        {
         printf("\t%s %s\t", all[x].plname,all[x].pfname);  
         x++;
        }
        printf("\n");
}
/*************************************************************************************/


/************** This section prints the second header for the Smoking Section ***********************/

    printf("\n\n");
    for (x = 0; x<80; x++)
        printf("*");            //Prints the asterisks in the heading
    printf("\n");
    for (x = 0; x<6; x++)
        printf("*");
    printf("\n");
    printf("*\t\t\tSmoking Section\n");
    printf("*\n");
    for (x = 0; x<80; x++)
        printf(".");

/********************   Prints the Smoking Section Seating Assignments  ********************************************/
for(x=0;x<10;x++)
{
    for(y=0;y<3;y++)        //print tests output for plane array
        printf("%c ",plane[x][y]);
    printf("\n");
}
x=0;    
for(a=0;a<10;a++)
{
    for(b=0;b<3;b++)    //print test for all array of structures
        {
        printf("%s %s\t", all[x].pfname,all[x].plname);
        x++;
        }
        printf("\n");
}
    printf("\n");
    x=0;

for(a=8;a<11;a++)
    {
    for(b=0;b<3;b++)   
        {
        printf("\t%s %s\t", assign[x].plname,assign[x].pfname);
        x++;
        }
        printf("\n");
    }
/********************** This section prints the third header for the Waiting List *******************************/
    printf("\n\n");
    for (x = 0; x<80; x++)
        printf("*");            //Prints the asterisks in the heading
    printf("\n");
    for (x = 0; x<6; x++)
        printf("*");
    printf("\n");
    printf("*\t\t\t\tWaiting List\n");
    printf("*\n");
    printf("*\tNAME\t\tSMOKING CHOICE\t\tROW\t\tCOLUMN\n");
    printf("*\n");
    for (x = 0; x<80; x++)
        printf(".");
/******************************     Prints the Waiting List Info    ********************************************************/
printf("\n");   
    x = 0;
for(a=0;a<11;a++)
    {
    printf("%i\t%s %s\t\t%c\t\t%i\t\t%i",(a+1),waiting[x].plname,waiting[x].pfname,waiting[x].stPref,waiting[x].row,waiting[x].col);
    x++;
    printf("\n");
    }
/************************************   End of Function *************************************************/
}
void seatPrgm()
{
    a=0;
    z=0;
    for(x=0;x<10;x++)
    {
        for(y=0;y<3;y++)                        //FIX THIS!!!!!!!!!!!!!!!!
        {    
            while((plane[x][y]) == 'E')      //While empty
            {
                if((all[z].stPref)=='N')
                {
                    (all[z] = assign[a+1]);     //Fills the assigned seats
                    (plane[x][y] == 'F');
                    z++;
                    a++;
                }

                else
                {
                    (all[z] = assign[a+1]);
                    (plane[x][y] == 'F');
                    z++;
                    a++;
                };
            };
            while(plane[x][y] == 'F')     //Puts them on the waiting list if that seat is already occupied or 'F' FULL.
            {
                while(z<41)
                {
                    (all[z] = waiting[z]);
                    z++;
                    a++;
                };
            };
        };
    };
}

0 个答案:

没有答案