C语言的问题在VC++环境下提示warning C4715: 'question_get' : not all control paths return a value
和warningC4101:'n':unreferencedlocalvariable这是我的程序,帮忙看一下,最好帮忙改一下,是一个小学生四则运算练习系统#includ...
和 warning C4101: 'n' : unreferenced local variable
这是我的程序,帮忙看一下,最好帮忙改一下,是一个小学生四则运算练习系统
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int question_get();
int type;
void main( void )
{
int answer,n;
srand( (unsigned)time( NULL ) );
loop:
printf( "请选择要进行测试的题目种类:" );
printf( "\n1.加法运算\n2.减法运算\n3.乘法运算\n4.除法运算\n5.退出运算\n" );
printf("\t\t\t请选择(1-5):");
scanf( "%d", &type );
while( 1 )
{
int temp;
int flag;
answer = question_get();
printf( "请回答:\n" );
scanf( "%d", &temp );
while( temp!=answer )
{
printf( "\n答案错误,重做\n" );
scanf( "%d", &temp );
}
printf( "\n答案正确,很好\n" );
printf( "继续请按1,退出请按0\n" );
scanf( "%d", &flag );
while( flag!=0&&flag!=1 )
{
printf( "按其它键无效\n" );
scanf( "%d", &flag );
}
if( flag==0 )
break;
goto loop;
} }
int question_get()
{
int a,b,c;
loop: if( type==1 ) {
a=rand()%99;
b=99-a;
b=rand()%b;
printf( "%d + %d = ?", a, b );
return(a+b);
}
else if( type==2 )
{
b=rand()%99;
c=99-b;
c=rand()%c;
printf( "%d - %d = ?", b+c, b );
return(c);
}
else if( type==3 )
{
a=rand()%10;
b=50-a;
b=rand()%b;
printf( "%d * %d = ?", a, b );
return(a*b);
}
else if( type==4 )
{
b=rand()%50;
c=100/b;
while( 1 )
{
c=rand()%c;
if( c!=0 )
break;
}
printf( "%d / %d = ?", b*c, b );
return(c);
}
else if( type==5 )
{
printf("\t\t\t退出系统\n"); /*结束程序*/
system("pause");
exit(0);
}
else if( type==0||type>5 )
{
printf("\t\t\t输入错误,请输入1-5内的数字\n");
printf("\t\t\t请选择(1-5):");
scanf( "%d", &type );
goto loop;
}
} 展开
这是我的程序,帮忙看一下,最好帮忙改一下,是一个小学生四则运算练习系统
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int question_get();
int type;
void main( void )
{
int answer,n;
srand( (unsigned)time( NULL ) );
loop:
printf( "请选择要进行测试的题目种类:" );
printf( "\n1.加法运算\n2.减法运算\n3.乘法运算\n4.除法运算\n5.退出运算\n" );
printf("\t\t\t请选择(1-5):");
scanf( "%d", &type );
while( 1 )
{
int temp;
int flag;
answer = question_get();
printf( "请回答:\n" );
scanf( "%d", &temp );
while( temp!=answer )
{
printf( "\n答案错误,重做\n" );
scanf( "%d", &temp );
}
printf( "\n答案正确,很好\n" );
printf( "继续请按1,退出请按0\n" );
scanf( "%d", &flag );
while( flag!=0&&flag!=1 )
{
printf( "按其它键无效\n" );
scanf( "%d", &flag );
}
if( flag==0 )
break;
goto loop;
} }
int question_get()
{
int a,b,c;
loop: if( type==1 ) {
a=rand()%99;
b=99-a;
b=rand()%b;
printf( "%d + %d = ?", a, b );
return(a+b);
}
else if( type==2 )
{
b=rand()%99;
c=99-b;
c=rand()%c;
printf( "%d - %d = ?", b+c, b );
return(c);
}
else if( type==3 )
{
a=rand()%10;
b=50-a;
b=rand()%b;
printf( "%d * %d = ?", a, b );
return(a*b);
}
else if( type==4 )
{
b=rand()%50;
c=100/b;
while( 1 )
{
c=rand()%c;
if( c!=0 )
break;
}
printf( "%d / %d = ?", b*c, b );
return(c);
}
else if( type==5 )
{
printf("\t\t\t退出系统\n"); /*结束程序*/
system("pause");
exit(0);
}
else if( type==0||type>5 )
{
printf("\t\t\t输入错误,请输入1-5内的数字\n");
printf("\t\t\t请选择(1-5):");
scanf( "%d", &type );
goto loop;
}
} 展开
展开全部
这是两个警告,不影响程序运行。
第一个警告是说,函数question_get存在不return返回值的分支,在这个函数里,也就是一系列的if else之后,剩余的情况(type < 0)没有得到处理,按照你代码的逻辑,最后一个else if(type ==0 || type==5)改成else,把后面的if()去掉就可以了。
第二个警告是说,函数main里,局部变量n定义了却没有被引用,把这个n删掉就可以了。
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int question_get();
int type;
void main( void )
{
int answer; /*删掉局部变量n*/
srand( (unsigned)time( NULL ) );
loop:
printf( "请选择要进行测试的题目种类:" );
printf( "\n1.加法运算\n2.减法运算\n3.乘法运算\n4.除法运算\n5.退出运算\n" );
printf("\t\t\t请选择(1-5):");
scanf( "%d", &type );
while( 1 )
{
int temp;
int flag;
answer = question_get();
printf( "请回答:\n" );
scanf( "%d", &temp );
while( temp!=answer )
{
printf( "\n答案错误,重做\n" );
scanf( "%d", &temp );
}
printf( "\n答案正确,很好\n" );
printf( "继续请按1,退出请按0\n" );
scanf( "%d", &flag );
while( flag!=0&&flag!=1 )
{
printf( "按其它键无效\n" );
scanf( "%d", &flag );
}
if( flag==0 )
break;
goto loop;
}
}
int question_get()
{
int a,b,c;
loop:
if( type==1 )
{
a=rand()%99;
b=99-a;
b=rand()%b;
printf( "%d + %d = ?", a, b );
return(a+b);
}
else if( type==2 )
{
b=rand()%99;
c=99-b;
c=rand()%c;
printf( "%d - %d = ?", b+c, b );
return(c);
}
else if( type==3 )
{
a=rand()%10;
b=50-a;
b=rand()%b;
printf( "%d * %d = ?", a, b );
return(a*b);
}
else if( type==4 )
{
b=rand()%50;
c=100/b;
while( 1 )
{
c=rand()%c;
if( c!=0 )
break;
}
printf( "%d / %d = ?", b*c, b );
return(c);
}
else if( type==5 )
{
printf("\t\t\t退出系统\n"); /*结束程序*/
system("pause");
exit(0);
}
else /*这里把if()删掉即可*/
{
printf("\t\t\t输入错误,请输入1-5内的数字\n");
printf("\t\t\t请选择(1-5):");
scanf( "%d", &type );
goto loop;
}
return -1; /*保险一点,最后加一个return语句,虽然实际走不到这里*/
}
展开全部
你这个不是错误,是警告,是提示你你的代码中的n定义了没有使用,你把n删除掉即可去除这个警告。如下:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int question_get();
int type;
int main()
{
int answer; /*去除n*/
srand( (unsigned)time( NULL ) );
loop:
printf( "请选择要进行测试的题目种类:" );
printf( "\n1.加法运算\n2.减法运算\n3.乘法运算\n4.除法运算\n5.退出运算\n" );
printf("\t\t\t请选择(1-5):");
scanf( "%d", &type );
while( 1 )
{
int temp;
int flag;
answer = question_get();
printf( "请回答:\n" );
scanf( "%d", &temp );
while( temp!=answer )
{
printf( "\n答案错误,重做\n" );
scanf( "%d", &temp );
}
printf( "\n答案正确,很好\n" );
printf( "继续请按1,退出请按0\n" );
scanf( "%d", &flag );
while( flag!=0&&flag!=1 )
{
printf( "按其它键无效\n" );
scanf( "%d", &flag );
}
if( flag==0 )
break;
goto loop;
}
return 0;
}
int question_get()
{
int a,b,c;
loop:
if( type==1 )
{
a=rand()%99;
b=99-a;
b=rand()%b;
printf( "%d + %d = ?", a, b );
return(a+b);
}
else if( type==2 )
{
b=rand()%99;
c=99-b;
c=rand()%c;
printf( "%d - %d = ?", b+c, b );
return(c);
}
else if( type==3 )
{
a=rand()%10;
b=50-a;
b=rand()%b;
printf( "%d * %d = ?", a, b );
return(a*b);
}
else if( type==4 )
{
b=rand()%50;
c=100/b;
while( 1 )
{
c=rand()%c;
if( c!=0 )
break;
}
printf( "%d / %d = ?", b*c, b );
return(c);
}
else if( type==5 )
{
printf("\t\t\t退出系统\n"); /*结束程序*/
system("pause");
exit(0);
}
else if( type==0||type>5 )
{
printf("\t\t\t输入错误,请输入1-5内的数字\n");
printf("\t\t\t请选择(1-5):");
scanf( "%d", &type );
goto loop;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询