要怎样缩短?
请大神们指点指点,我的程序码很乱请慢慢看@@全部选择只有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");
}
}