| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 476 人关注过本帖
标题:C程序,同样的列表出现两次,找不到错误!
取消只看楼主 加入收藏
chaicai333
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2014-1-20
结帖率:50%
收藏
已结贴  问题点数:18 回复次数:0 
C程序,同样的列表出现两次,找不到错误!
请高手帮我看这个吗?
全部例子选项你选1,1,1,1,1
然后跳回去主菜单时 你选3.generatebill
做么会有2个table的???还有我的sport名字为什么显示没有的?变成null了
程序代码:
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>

char pasword[10], usrname[10], ch, day[10], sportname[20];
int i, menu1, picktime, qq, select, dayy,amount;

struct badminton{
    char *bad[20];
}p[10], np[10];
struct squash{
    char *squ[20];
}a1[10], a2[10];
struct tennis{
    char *ten[20];
}b1[10], b2[10];
struct futsal{
    char *fut[20];
}c1[10], c2[10];
void print_line(int time)
{
    switch (time)
    {

    case 1: {
                printf("|-------------------------------------------------------------------|\n");
    }break;

    case 2: {
                printf("|---------------------------------------------|\n");
    }break;
    }
}
void print_header(int time)
{
    switch (time)
    {

    case 1: {
                printf("|   court  |  7am-9am |  9am-11am |  11am-1pm |  1pm-3pm |  3pm-5pm |\n");

    }break;

    case 2: {
                printf("|    court  | 5pm-7pm  | 7pm-9pm  | 9pm-10pm  |\n");
    }break;
    }
}
void print_header2(int time)
{
    switch (time)
    {

    case 1: {
                printf("|    court  |  10am-12am  |  12pm-2pm  |  2pm-4pm  |  4pm-5pm    |\n");

    }break;

    case 2: {
                printf("|    court  | 5pm-7pm  | 7pm-9pm  | 9pm-10pm  |\n");
    }break;
    }
}
void print_header3(int time)
{
    switch (time)
    {

    case 1: {
                printf("|   court  |   8am-10am  |  10am-12pm  |  12pm-2pm  |  2pm-4pm  |  4pm-5pm  |\n");

    }break;

    case 2: {
                printf("|    court  | 5pm-7pm  | 7pm-9pm  | 9pm-10pm  |\n");
    }break;
    }
}
void print_header4(int time)
{
    switch (time)
    {

    case 1: {
                printf("|   court  |  7am-9am  |  9am-11am  |  11am-1pm  |  1pm-3pm  |  3pm-5pm |\n");

    }break;

    case 2: {
                printf("|    court  | 5pm-7pm  | 7pm-9pm  | 9pm-10pm  |\n");
    }break;
    }
}
void bill_content(int menu){
    printf("|     %s     |          %d         ", sportname[20], amount);
    switch (menu){
    case 1:{printf("|  Rm16.00   |\n"); }break;
    case 2:{printf("|  Rm10.00   |\n"); }break;
    case 3:{printf("|  Rm30.00   |\n"); }break;
    case 4:{printf("|  Rm40.00   |\n"); }break;
    }
}
void print_content(char *court, int time, int start_index){
    char *space;
    printf("|      %s    |", court);
    switch (time){
    case 1:{
               for (int i = 0; i < 5; i++)
               {
                   if (start_index + i < 10)
                   {
                       space = " ";
                       printf("    %d. %s%s  ", start_index + i, np[dayy].bad[start_index + i - 1], space);
                   }

                   else
                   {
                       printf("    %d. %s  ", start_index + i, np[dayy].bad[start_index + i - 1]);
                   }

               }
               printf("|\n");
    }break;

    case 2:{
               for (int i = 0; i < 3; i++)
               {
                   if (start_index + i < 10)
                   {
                       space = " ";
                       printf("    %d. %s%s  ", start_index + i, p[dayy].bad[start_index + i - 1], space);
                   }

                   else
                   {
                       printf("    %d. %s  ", start_index + i, p[dayy].bad[start_index + i - 1]);
                   }
               }
               printf("|\n");
    }break;

    }
}
void print_content2(char *court, int time, int start_index){
    char *space;
    printf("|      %s    |", court);
    switch (time){
    case 1:{
               for (int i = 0; i < 4; i++)
               {
                   if (start_index + i < 10)
                   {
                       space = " ";
                       printf("    %d. %s%s  ", start_index + i, a1[dayy].squ[start_index + i - 1], space);
                   }

                   else
                   {
                       printf("    %d. %s  ", start_index + i, a1[dayy].squ[start_index + i - 1]);
                   }

               }
               printf("|\n");
    }break;

    case 2:{
               for (int i = 0; i < 3; i++)
               {
                   if (start_index + i < 10)
                   {
                       space = " ";
                       printf("    %d. %s%s  ", start_index + i, a2[dayy].squ[start_index + i - 1], space);
                   }

                   else
                   {
                       printf("    %d. %s  ", start_index + i, a2[dayy].squ[start_index + i - 1]);
                   }
               }
               printf("|\n");
    }break;

    }
}
void print_content3(char *court, int time, int start_index){
    char *space;
    printf("|      %s    |", court);
    switch (time){
    case 1:{
               for (int i = 0; i < 5; i++)
               {
                   if (start_index + i < 10)
                   {
                       space = " ";
                       printf("    %d. %s%s  ", start_index + i, b1[dayy].ten[start_index + i - 1], space);
                   }

                   else
                   {
                       printf("    %d. %s  ", start_index + i, b1[dayy].ten[start_index + i - 1]);
                   }

               }
               printf("|\n");
    }break;

    case 2:{
               for (int i = 0; i < 3; i++)
               {
                   if (start_index + i < 10)
                   {
                       space = " ";
                       printf("    %d. %s%s  ", start_index + i, b2[dayy].ten[start_index + i - 1], space);
                   }

                   else
                   {
                       printf("    %d. %s  ", start_index + i, b2[dayy].ten[start_index + i - 1]);
                   }
               }
               printf("|\n");
    }break;

    }
}
void print_content4(char *court, int time, int start_index){
    char *space;
    printf("|      %s    |", court);
    switch (time){
    case 1:{
               for (int i = 0; i < 5; i++)
               {
                   if (start_index + i < 10)
                   {
                       space = " ";
                       printf("    %d. %s%s  ", start_index + i, c1[dayy].fut[start_index + i - 1], space);
                   }

                   else
                   {
                       printf("    %d. %s  ", start_index + i, c1[dayy].fut[start_index + i - 1]);
                   }

               }
               printf("|\n");
    }break;

    case 2:{
               for (int i = 0; i < 3; i++)
               {
                   if (start_index + i < 10)
                   {
                       space = " ";
                       printf("    %d. %s%s  ", start_index + i, c2[dayy].fut[start_index + i - 1], space);
                   }

                   else
                   {
                       printf("    %d. %s  ", start_index + i, c2[dayy].fut[start_index + i - 1]);
                   }
               }
               printf("|\n");
    }break;

    }
}
void print_badminton_table(int time)
{
    switch (menu1){
    case 1:{
               print_line(time);
               print_header(time);
               print_line(time);
               print_content("A", time, 1);
               print_line(time);
               print_content("B", time, 6);
               print_line(time);
               print_content("C", time, 11);
               print_line(time);
               print_content("D", time, 16);
               print_line(time);
    }break;
    case 2:{
               print_line(time);
               print_header2(time);
               print_line(time);
               print_content2("A", time, 1);
               print_line(time);
               print_content2("B", time, 4);
               print_line(time);
    }break;
    case 3:{
               print_line(time);
               print_header3(time);
               print_line(time);
               print_content3("A", time, 1);
               print_line(time);
               print_content3("B", time, 6);
               print_line(time);
               print_content3("C", time, 11);
               print_line(time);
    }break;
    case 4:{
               print_line(time);
               print_header(time);
               print_line(time);
               print_content4("A", time, 1);
               print_line(time);
               print_content4("B", time, 6);
               print_line(time);
               print_content4("C", time, 11);
               print_line(time);
    }break;
    }
}

void chooseday(){
    printf("Which day?");
    scanf("%s", &day);
    if (!strcmp(day, "monday"))
    {
        printf("Monday is off day !\nPlease choose another day!");
        scanf("%s", &day);
    }
    else if (!strcmp(day, "tuesday")){
        dayy = 1;
    }
    else if (!strcmp(day, "wednesday")){
        dayy = 2;
    }
    else if (!strcmp(day, "thursday")){
        dayy = 3;
    }
    else if (!strcmp(day, "friday")){
        dayy = 4;
    }
    else if (!strcmp(day, "saturday")){
        dayy = 5;
    }
    system("cls");

    {
        printf("You have choose %s\nPlease pick a time\n", day);
        printf("1.None Peak time\n");
        printf("2.Peak time\n");
        scanf("%d", &picktime);

    }
}

void checkcourt(){
    printf("1.Badminton\n");
    printf("2.Squash\n");
    printf("3.Tennis\n");
    printf("4.Futsal\n");
    scanf("%d", &menu1);
    system("cls");
    printf("How many court you want to book?");
    scanf("%d", &amount);
    
    if (menu1 == 1){
        sportname[10] = "Badminton";
        chooseday();
        int amountx;
        for (amountx = 0; amountx < amount; amountx++)
        {
            print_badminton_table(picktime);
            printf("Please insert the court");
            scanf("%d", &qq);
            system("cls");
            printf("You successsfully have booked a court.\n");
            switch (picktime){


            case 1:{
                       np[dayy].bad[qq - 1] = "X";
                       print_badminton_table(picktime);
                       getch();
                       
            }break;
            case 2:{
                       p[dayy].bad[qq - 1] = "X";
                       print_badminton_table(picktime);
                       getch();
            }break;

            }
        }mainmenu();
    }
        else if (menu1 == 2){
            sportname[10] = "Squash";
            chooseday();
            int amountx;
            for (amountx = 0; amountx < amount; amountx++){
                print_badminton_table(picktime);
                printf("Please insert the court");
                scanf("%d", &qq);
                system("cls");
                printf("You successsfully have booked a court.\n");
                switch (picktime){

                case 1:{
                           a1[dayy].squ[qq - 1] = "X";
                           print_badminton_table(picktime);
                           getch();
                          
                }
                case 2:{
                           a2[dayy].squ[qq - 1] = "X";
                           print_badminton_table(picktime);
                           getch();
                           
                }
                }
            }mainmenu();
        }
        else if (menu1 == 3){
            sportname[10] = "Tennis";
            chooseday();
            int amountx;
            for (amountx = 0; amountx < amount; amountx++){
                print_badminton_table(picktime);
                printf("Please insert the court");
                scanf("%d", &qq);
                system("cls");
                printf("You successsfully have booked a court.\n");
                switch (picktime){

                case 1:{
                           b1[dayy].ten[qq - 1] = "X";
                           print_badminton_table(picktime);
                           getch();
                           
                }
                case 2:{
                           b2[dayy].ten[qq - 1] = "X";
                           print_badminton_table(picktime);
                           getch();
                          
                }
                }
            }mainmenu();
        }
        else if (menu1 == 4){
            sportname[10] = "Futsal";
            chooseday();
            int amountx;
            for (amountx = 0; amountx < amount; amountx++){
                print_badminton_table(picktime);
                printf("Please insert the court");
                scanf("%d", &qq);
                system("cls");
                printf("You successsfully have booked a court.\n");
                switch (picktime){

                case 1:{
                           c1[dayy].fut[qq - 1] = "X";
                           print_badminton_table(picktime);
                           getch();
                          
                }
                case 2:{
                           c2[dayy].fut[qq - 1] = "X";
                           print_badminton_table(picktime);
                           getch();
                           
                }
                }
            }mainmenu();
        }
        else{}
    
}
void generatebill()
{
    printf("\n");
    printf("\n");
    printf("\n");
    printf("         Genome Sport Centre                               Bill No:\n");
    printf("         No.123,Sri Petaling,\n");
    printf("         Kuala Lumpur\n");
    printf("         Tel:03-89119223\n");
    printf("         Staff:%s                                          Day:%s\n", usrname, day);
    printf("\n");
    printf("                                 Booking Table\n");
    printf("       "); print_line(1);
    printf("       "); printf("|      Sport     |  Number of booking |     Rate    |  Total  |\n");
    printf("       "); print_line(1);
    printf("       "); bill_content(menu1);
    printf("       "); print_line(1);    
    
}
int mainmenu(){
    int menu2;
    system("cls");
    printf("1.Check court availability\n");
    printf("2.Booking\n");
    printf("3.Generate bill\n");
    printf("4.Exit\n");
    scanf("%d", &menu2);
    system("cls");
    switch (menu2){
    case 1:{
               checkcourt();
    }
    case 3:{
               generatebill();
    }
    }
}

int main(){
    int b;
    int a;
    for (a = 0; a < 20; a++){
        for (b = 0; b < 10; b++){
            np[b].bad[a] = "O";
            p[b].bad[a] = "O";
            a1[b].squ[a] = "O";
            a2[b].squ[a] = "O";
            b1[b].ten[a] = "O";
            b2[b].ten[a] = "O";
            c1[b].fut[a] = "O";
            c2[b].fut[a] = "O";
        }
    }

    printf("Enter User name: ");
    gets(usrname);
    printf("Enter the password : ");

    for (i = 0; i < 10; i++)
    {
        ch = getch();

        if (isprint(ch))
        {
            pasword[i] = ch;
            ch = '*';
            printf("%c", ch);
        }
        else
        {
            pasword[i] = '\0';
            break;
        }
    }
    if (!strcmp(pasword, "class"))
    {
        printf("\n\naccess\n");
        mainmenu();
    }
    else
    {
        printf("\n\nno access\n");
    }
}


[ 本帖最后由 chaicai333 于 2014-1-23 20:45 编辑 ]
搜索更多相关主题的帖子: null 
2014-01-23 19:53
快速回复:C程序,同样的列表出现两次,找不到错误!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.046593 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved