c语言制作二级菜单,报错一下午,小白很迷茫
#include <stdlib.h>#include <stdio.h>
void nemu1();
void nemu2();
int main()
{int x;
while(1);
{system("cls");
printf("\n\n\n\n\n\n\n\n");
printf("\t\t\t\t\t1:顺序表\n");
printf("\t\t\t\t\t2:链表\n");
printf("\t\t\t\t\t3:退出\n");
printf("\n\t\t\t\t\t请输入您的选择(1-3)=:");
scanf("%d",&x);
}
switch(x)
{case 1:nemu1(); break;
case 2:nemu2(); break;
default:printf("error"); break;}
return 1;
}
void menu1();
{int y;
while(1)
{system("cls");
printf("\n\n\n\n\n\n\n\n");
printf("\t\t\t\t\t1:创建顺序线性表\n");
printf("\t\t\t\t\t2:求顺序线性表的长度\n");
printf("\t\t\t\t\t3:按序号取顺序表元素\n");
printf("\t\t\t\t\t4:按值查找顺序表\n");
printf("\t\t\t\t\t5:插入元素\n");
printf("\t\t\t\t\t6:删除元素\n");
printf("\t\t\t\t\t7:输出顺序线性表\n");
printf("\t\t\t\t\t8:返回\n");
printf("\t\t\t\t\t\t请输入您的选择(1-8)=:");
scanf("%d",&y);}
if(y==8) break;
switch(y)
{ case 1:printf("这里是创建顺序线性表"); break;
case 2:printf("这里是求顺序线性表的长度");break;
case 3:printf("这里是按序号取顺序表元素"); break;
case 4:printf("这里是按值查找顺序表"); break;
case 5:printf("这里是插入元素"); break;
case 6:printf("这里是删除元素"); break;
case 7:printf("这里是输出顺序线性表"): break;
default:printf("error"); break;}
return 1;
}
void menu2();
{int z;
while(1)
{system("cls");
printf("\n\n\n\n\n\n\n\n");
printf("\t\t\t\t\t1:创建链式线性表\n");
printf("\t\t\t\t\t2:求链式线性表的长度\n");
printf("\t\t\t\t\t3:按序号取链表元素\n");
printf("\t\t\t\t\t4:按序号取链表元素\n");
printf("\t\t\t\t\t5:插入元素\n");
printf("\t\t\t\t\t6:删除元素\n");
printf("\t\t\t\t\t7:输出链式线性表\n");
printf("\t\t\t\t\t8:返回\n");
printf("\t\t\t\t\t\t请输入您的选择(1-8)=:");
scanf("%d",&z);}
if(z==8) break;
switch(x)
{ case 1:printf("这里是创建链式线性表"); break;
case 2:printf("这里是求链式线性表的长度"); break;
case 3:printf("这里是按序号取链表元素"); break;
case 4:printf("这里是按序号取链表元素"); break;
case 5:printf("这里是插入元素"); break;
case 6:printf("这里是删除元素"); break;
case 7:printf("这里是输出链式线性表");break;
default:printf("error"); break;}
return 1;
} return 1 改成return 0 chxchxkkk 发表于 2020-2-23 11:00
return 1 改成return 0
您的函数声明是返回一个空值 ,您在最后就返回了一个1的整数
两个方法:1.是把函数声明改成INT 类型,2是把return 1;改成return ; 或者不反回,去掉return 语句。 把1函数给您做了一个调整,您看一下,下次写代码还是严谨点,函数声明与函数体的函数名都不一样。
#include <stdlib.h>
#include <stdio.h>
void menu1();
void menu2();
int main()
{
int x;
do
{
system("cls");
printf("\n\n\n\n\n\n\n\n");
printf("\t\t\t\t\t1:顺序表\n");
printf("\t\t\t\t\t2:链表\n");
printf("\t\t\t\t\t3:退出\n");
printf("\n\t\t\t\t\t请输入您的选择(1-3)=:");
re:
scanf("%d",&x);
switch(x)
{
case 1:
menu1();
break;
case 2:
menu2();
break;
case 3:
exit(1);
break;
default:
printf("error Please reput input:");
goto re;
break;
}
}while(1);
return 0;
}
void menu1()
{
int y;
system("cls");
printf("\n\n\n\n\n\n\n\n");
printf("\t\t\t\t\t1:创建顺序线性表\n");
printf("\t\t\t\t\t2:求顺序线性表的长度\n");
printf("\t\t\t\t\t3:按序号取顺序表元素\n");
printf("\t\t\t\t\t4:按值查找顺序表\n");
printf("\t\t\t\t\t5:插入元素\n");
printf("\t\t\t\t\t6:删除元素\n");
printf("\t\t\t\t\t7:输出顺序线性表\n");
printf("\t\t\t\t\t8:返回\n");
do
{
printf("\t\t\t\t\t\t请输入您的选择(1-8)=:");
reTwo:
scanf("%d",&y);
switch(y)
{
case 1:
printf("这里是创建顺序线性表"); break;
case 2:
printf("这里是求顺序线性表的长度");break;
case 3:
printf("这里是按序号取顺序表元素"); break;
case 4:
printf("这里是按值查找顺序表"); break;
case 5:
printf("这里是插入元素"); break;
case 6:
printf("这里是删除元素"); break;
case 7:
printf("这里是输出顺序线性表"); break;
case 8:
return ;
break;
default:
printf("error");
goto reTwo;
break;
}
}while(1);
return ;
}
void menu2()
{
int z;
while(1)
{
system("cls");
printf("\n\n\n\n\n\n\n\n");
printf("\t\t\t\t\t1:创建链式线性表\n");
printf("\t\t\t\t\t2:求链式线性表的长度\n");
printf("\t\t\t\t\t3:按序号取链表元素\n");
printf("\t\t\t\t\t4:按序号取链表元素\n");
printf("\t\t\t\t\t5:插入元素\n");
printf("\t\t\t\t\t6:删除元素\n");
printf("\t\t\t\t\t7:输出链式线性表\n");
printf("\t\t\t\t\t8:返回\n");
printf("\t\t\t\t\t\t请输入您的选择(1-8)=:");
scanf("%d",&z);
}
// if(z==8) break;
switch(z)
{
case 1:printf("这里是创建链式线性表"); break;
case 2:printf("这里是求链式线性表的长度"); break;
case 3:printf("这里是按序号取链表元素"); break;
case 4:printf("这里是按序号取链表元素"); break;
case 5:printf("这里是插入元素"); break;
case 6:printf("这里是删除元素"); break;
case 7:printf("这里是输出链式线性表");break;
default:printf("error"); break;
}
return ;
}
页:
[1]