| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 402 人关注过本帖
标题:要怎样缩短?
取消只看楼主 加入收藏
chaicai333
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2014-1-20
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:4 
要怎样缩短?
请大神们指点指点,我的程序码很乱请慢慢看@@
全部选择只有1是做好的,所以全部都请按1.
问题是这样的,我有很多个table(不懂华语叫什么)
要怎样外main外面做一个个别的function给我的table,然后当我用的时候,就用那个function就可以了


#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
struct badminton_none{
    int bad1, bad2, bad3, bad4, bad5;

};

struct badminton_none q1;
bad1 = "0", bad2 = "0", bad3 = "0", bad4 = "0", bad5 = "0";

void mainmenu(){
    printf("1.Check court availability\n");
    printf("2.Booking\n");
    printf("3.Generate bill\n");
    printf("4.Exit\n");

}
int main()
{

    char pasword[10], usrname[10], ch;
    char day[10];
    int i, menu1, badminton, qq;

    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");
        system("cls");
        mainmenu();

        scanf("%d", &menu1);
        system("cls");
        switch (menu1){

        case 1:{
                   printf("1.Badminton\n");
                   printf("2.Squash\n");
                   printf("3.Tennis\n");
                   printf("4.Futsal\n");
                   scanf("%d", &menu1);
                   system("cls");

                   if (menu1 == 1){

                       printf("Which day?");
                       scanf("%s", &day);
                       while (!strcmp(day, "monday"))
                       {
                           printf("Monday is off day !\nPlease choose another day!");
                           scanf("%s", &day);
                       }

                       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", &badminton);

                       }

                     


                       switch (badminton){
                       case 1:{
                                  printf("|---------------------------------------------------------------|\n");
                                  printf("|    court  | 7am-9am | 9am-11am | 11am-1pm | 1pm-3pm | 3pm-5pm |\n");
                                  printf("|---------------------------------------------------------------|\n");
                                  printf("|      A    |   1. %s     2. %s      3. %s         4. %s     5. %s   |\n", q1.bad1, q1.bad2, q1.bad3, q1.bad4, q1.bad5);
                                  printf("|---------------------------------------------------------------|\n");
                                  printf("|      B    |                                                   |\n");
                                  printf("|---------------------------------------------------------------|\n");
                                  printf("|      C    |                                                   |\n");
                                  printf("|---------------------------------------------------------------|\n");
                                  printf("|      D    |                                                   |\n");
                                  printf("|---------------------------------------------------------------|\n");
                                  printf("Please insert the court");
                                  scanf("%d", &qq);
                                  system("cls");
                                  switch (qq){
                                  case 1: {
                                              printf("You successsfully have booked a court.\n");
                                              q1.bad1 = "X";
                                              printf("|---------------------------------------------------------------|\n");
                                              printf("|    court  | 7am-9am | 9am-11am | 11am-1pm | 1pm-3pm | 3pm-5pm |\n");
                                              printf("|---------------------------------------------------------------|\n");
                                              printf("|      A    |    %s         %s         %s        %s        %s        |\n", q1.bad1, q1.bad2, q1.bad3, q1.bad4, q1.bad5);
                                              printf("|---------------------------------------------------------------|\n");
                                              printf("|      B    |                                                   |\n");
                                              printf("|---------------------------------------------------------------|\n");
                                              printf("|      C    |                                                   |\n");
                                              printf("|---------------------------------------------------------------|\n");
                                              printf("|      D    |                                                   |\n");
                                              printf("|---------------------------------------------------------------|\n");


                                              return main();
                                  }break;
                                  case 2: {
                                              printf("You successsfully have booked a court.");
                                              q1.bad2 = "X";
                                              printf("|---------------------------------------------------------------|\n");
                                              printf("|    court  | 7am-9am | 9am-11am | 11am-1pm | 1pm-3pm | 3pm-5pm |\n");
                                              printf("|---------------------------------------------------------------|\n");
                                              printf("|      A    |    %s         %s         %s        %s        %s        |\n", q1.bad1, q1.bad2, q1.bad3, q1.bad4, q1.bad5);
                                              printf("|---------------------------------------------------------------|\n");
                                              printf("|      B    |                                                   |\n");
                                              printf("|---------------------------------------------------------------|\n");
                                              printf("|      C    |                                                   |\n");
                                              printf("|---------------------------------------------------------------|\n");
                                              printf("|      D    |                                                   |\n");
                                              printf("|---------------------------------------------------------------|\n");
                                  }break;



                                  }

                       }break;

                       case 2:{
                                  printf("|------------------------------------------|\n");
                                  printf("|    court  | 5pm-7pm | 7pm-9pm | 9pm-10pm |\n");
                                  printf("|------------------------------------------|\n");
                                  printf("|      A    |                              |\n");
                                  printf("|------------------------------------------|\n");
                                  printf("|      B    |                              |\n");
                                  printf("|------------------------------------------|\n");
                                  printf("|      C    |                              |\n");
                                  printf("|------------------------------------------|\n");
                                  printf("|      D    |                              |\n");
                                  printf("|------------------------------------------|\n");

                       }break;
                       }

                   }
                   else if (menu1 == 2)
                   {
                       printf("Which day?");
                       scanf("%s", &day);
                       while (!strcmp(day, "monday"))
                       {
                           printf("Monday is off day !\nPlease choose another day!");
                           scanf("%s", &day);
                       }

                       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", &badminton);
                       }

                       switch (badminton){

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

                   }
                   else if (menu1 == 3)
                   {
                       printf("Which day?");
                       scanf("%s", &day);
                       while (!strcmp(day, "monday"))
                       {
                           printf("Monday is off day !\nPlease choose another day!");
                           scanf("%s", &day);
                       }

                       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", &badminton);
                       }

                       switch (badminton){

                       case 1:{
                                  printf("|---------------------------------------------------------------------------|\n");
                                  printf("|    court  |  8am-10am  |  10am-12pm  |  12pm-2pm  |  2pm-4pm  |  4pm-5pm  |\n");
                                  printf("|---------------------------------------------------------------------------|\n");
                                  printf("|      A    |                                                               |\n");
                                  printf("|---------------------------------------------------------------------------|\n");
                                  printf("|      B    |                                                               |\n");
                                  printf("|---------------------------------------------------------------------------|\n");
                                  printf("|      c    |                                                               |\n");
                                  printf("|---------------------------------------------------------------------------|\n");
                       }
                       case 2:{
                                  printf("|---------------------------------------------------------------|\n");
                                  printf("|    court  |     5pm-7pm    |     7pm-9pm    |     9pm-10pm    |\n");
                                  printf("|---------------------------------------------------------------|\n");
                                  printf("|      A    |                                                   |\n");
                                  printf("|---------------------------------------------------------------|\n");
                                  printf("|      B    |                                                   |\n");
                                  printf("|---------------------------------------------------------------|\n");
                                  printf("|      c    |                                                   |\n");
                                  printf("|---------------------------------------------------------------|\n");
                       }
                       }
                   }
                   else if (menu1 == 4){

                       printf("Which day?");
                       scanf("%s", &day);
                       while (!strcmp(day, "monday"))
                       {
                           printf("Monday is off day !\nPlease choose another day!");
                           scanf("%s", &day);
                       }

                       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", &badminton);
                       }

                       switch (badminton){

                       case 1:{
                                  printf("|---------------------------------------------------------------------------|\n");
                                  printf("|    court  |  7am-9am  |  9am-11am  |  11am-1pm  |  1pm-3pm  |  3pm-5pm    |\n");
                                  printf("|---------------------------------------------------------------------------|\n");
                                  printf("|      A    |                                                               |\n");
                                  printf("|---------------------------------------------------------------------------|\n");
                                  printf("|      B    |                                                               |\n");
                                  printf("|---------------------------------------------------------------------------|\n");
                                  printf("|      c    |                                                               |\n");
                                  printf("|---------------------------------------------------------------------------|\n");
                       }
                       case 2:{
                                  printf("|---------------------------------------------------------------|\n");
                                  printf("|    court  |     5pm-7pm    |     7pm-9pm    |     9pm-10pm    |\n");
                                  printf("|---------------------------------------------------------------|\n");
                                  printf("|      A    |                                                   |\n");
                                  printf("|---------------------------------------------------------------|\n");
                                  printf("|      B    |                                                   |\n");
                                  printf("|---------------------------------------------------------------|\n");
                                  printf("|      c    |                                                   |\n");
                                  printf("|---------------------------------------------------------------|\n");
                       }
                       }
                   }
                   else{}
        }
        }
    }
    else
    {
        printf("\n\nno access\n");
    }
}
搜索更多相关主题的帖子: include function 
2014-01-20 19:02
chaicai333
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2014-1-20
收藏
得分:0 
回复 3楼 so_love
可以给我一个例子吗?因为老师是用英文教的所以我也不知道你说得用函数是哪一个
是类似
void function1()
{
int x
}
酱的东西吗?
2014-01-20 19:58
chaicai333
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2014-1-20
收藏
得分:0 
我的code有很多用printf做的table
请问如果我1个table我要用在个别7天,也就是每天都是有自己的table,怎样才可以让它分成7次?
就好像
struct badminton(){
         int x;
}
then 我可以
struct badminton 1;
int x = 5;
stuct badminton 2;
int x= 6;
可以把我的table做的类似酱嘛?酱我就不用酱麻烦写到酱多table了

程序代码:
void badtable(){
        printf("|---------------------------------------------------------------|\n");
        printf("|    court  | 7am-9am | 9am-11am | 11am-1pm | 1pm-3pm | 3pm-5pm |\n");
        printf("|---------------------------------------------------------------|\n");
        printf("|      A    |   1. %s     2. %s      3. %s        4. %s     5. %s   |\n", q1.bad1, q1.bad2, q1.bad3, q1.bad4, q1.bad5);
        printf("|---------------------------------------------------------------|\n");
        printf("|      A    |   6. %s     7. %s      8. %s        9. %s     10. %s   |\n", q1.bad1, q1.bad2, q1.bad3, q1.bad4, q1.bad5);
        printf("|---------------------------------------------------------------|\n");
        printf("|      A    |   11. %s    12. %s     13. %s       14. %s    15. %s   |\n", q1.bad1, q1.bad2, q1.bad3, q1.bad4, q1.bad5);
        printf("|---------------------------------------------------------------|\n");
        printf("|      A    |   16. %s    17. %s     18. %s       19. %s    20. %s   |\n", q1.bad1, q1.bad2, q1.bad3, q1.bad4, q1.bad5);
        printf("|---------------------------------------------------------------|\n");
2014-01-20 19:59
chaicai333
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2014-1-20
收藏
得分:0 
回复 6楼 so_love
那...那我在第5楼说的问题要有什么方式解决呢???
2014-01-20 20:16
chaicai333
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2014-1-20
收藏
得分:0 
还有本来有一段我是这样写的
程序代码:
struct badminton_none{
    char *bad1, *bad2, *bad3, *bad4, *bad5;
};

void main(){
struct badminton_none q1;
q1.bad1 = "0", q1.bad2 = "0", q1.bad3 = "0", q1.bad4 = "0", q1.bad5 = "0";
}


请问一下要怎样吧这段
struct badminton_none q1;
q1.bad1 = "0", q1.bad2 = "0", q1.bad3 = "0", q1.bad4 = "0", q1.bad5 = "0";
写在外面呢?
我写在外面后,q1.她就给我画红线,好像是declare(定义变数?)不到的关系,要怎样弄?
2014-01-20 20:25
快速回复:要怎样缩短?
数据加载中...
 
   



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

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