~~ 我编的这个程序主要是是最后错了错误`~`
`我希望程序要做的事情完成后` ~~出现一个选择``提示我们是不是~再运行一次程序`~再用一次程序``
我把提示程序提取出来了`~:
#include<stdio.h>
void yc(void);
void ifw(void); /*当输入错误时`提示重新输入*/
void welcome(void); /*退出程序时的一段输出*/
char gorq(void); /*提示用户是否还想继续运行程序*/
int main()
{
char b;
begain:b=gorq(); /*调用提示*/
/*如果想再运行就输入Y(y),想退出就输入N(n)*/
end:if ( (b=='y') || (b=='Y') )
goto begain;
else if ( (b=='n') || (b=='N') )
welcome();
else {
ifw();
scanf("%c",&b);
goto end;
}
printf ("\n\n\n\n"); /*这个是用反复来调试程序时~不会看晕用的.可以不看.*/
return 0;
}
/*表示欢迎使用*/
void welcome()
{
printf ("~.~ Welcome to use ~.~\n");
printf ("~.~ Welcome to use ~.~\n");
printf ("~.~ Welcome to use ~.~\n");
printf ("~.~ Welcome to use ~.~\n");
}
/*提示用户进行选择*/
char gorq(void)
{
char b;
printf ("Do you want to go on change?\n\n");
printf ("Chose Y to go on.\n");
printf ("Chose N to get out.\n");
scanf ("%c",&b);
return b;
}
/*输入错误时的提示*/
void ifw(void)
{
printf ("\n\nWrong chosing!!!\n");
printf ("Please chose again.\n");
yc();
}
void yc(void)
{
printf ("Your chosing is:");
}
程序出错在与`~除了输入N或n没错以外`~
输入其他非N(n)或非Y(y)~~时~~回出现 2 次输入错误提示`~
而输入Y或y时~~程序回从头再来一次`~但是回多出一个 输入错误提示(当程序第一次执行完后``走到这里也会自然的回多
出 输入错误提示)
很麻烦的是我用了GOTO`~~
因为想不到用别的什么方法了``
请各位朋友指出错误`~给点提示``多谢多谢`
能给经验的~~多多传授~`THANKS~~`
如果需要原来的整段代码``
就在下面`` 这个程序用来转换华氏与摄氏温度`~
先选华转为摄`~还是摄转为华```
然后选单个的温度转换``还是连续的多个温度转换``
#include<stdio.h>
void caidan(void); /*一级菜单``选华转摄或摄转华*/
void cftc(void); /*二级菜单``华转摄``选单个温度转换或是多个连续温度转换*/
void cctf(void); /*二级菜单``摄转华``选单个温度转换或是多个连续温度转换*/
void foto(void); /*华转摄```单个温度转换*/
void fsts(void); /*华转摄```多个温度转换*/
void coto(void); /*摄转华```单个温度转换*/
void csts(void); /*摄转华```多个温度转换*/
void yc(void); /*下面的函数上面已经说过了*/
void bar(void);
void ifw(void);
void welcome(void);
char gorq(void);
int main()
{
int c;
char b;
/*调用菜单选1 华转摄 选2 摄转华 不是1也不是2 提示是如错误 重新输入*/
begain:caidan();
yc();
scanf("%d",&c);
printf("\n");
mid:if ( c == 1 )
cftc();
else if ( c == 2 )
cctf();
else
{
ifw();
scanf("%d",&c);
goto mid;
}
/*转换完后``提示用户还是否再次转换*/
b=gorq();
end:if ( (b=='y') || (b=='Y') )
goto begain;
else if ( (b=='n') || (b=='N') )
welcome();
else
{
ifw();
scanf("%c",&b);
goto;
}
return 0;
}
void welcome()
{
printf("~.~ Welcome to use ~.~\n");
printf("~.~ Welcome to use ~.~\n");
printf("~.~ Welcome to use ~.~\n");
printf("~.~ Welcome to use ~.~\n");
}
char gorq(void)
{
char b;
printf ("Do you want to go on change?\n\n");
printf ("Chose Y to go on.\n");
printf ("Chose N to get out.\n");
scanf ("%c",&b);
return b;
}
/*一级菜单*/
void caidan(void)
{
bar();
printf (" This is a programing of changing fahr and celsisu. \n");
printf (" Please chose your thinking. \n");
printf (" 1.Fahr chagened into celsisu. \n");
printf (" 2.Celsisu changened into Fahr. \n");
bar();
printf("\n");
}
void ifw(void)
{
printf ("Wrong chosing!!!\n");
printf ("Please chose again.\n");
yc();
}
void yc(void)
{
printf ("Your chosing is:");
}
void bar(void)
{
printf ("**************************************************************\n");
}
/*二级菜单*/
void cftc(void)
{
int c;
bar();
printf ("Which way do you want to chose to change?\n");
printf (" 1.Put one f,get one c. \n");
printf (" 2.Put from f1 to f2,get from c1 to c2. \n");
bar();
printf ("\n");
yc();
scanf ("%d",&c);
printf("\n");
here:if ( c == 1 )
foto();
else if ( c == 2 )
fsts();
else
{
ifw();
scanf("%d",&c);
goto here;
}
}
/*同上*/
void cctf(void)
{
int c;
bar();
printf ("Which way do you want to chose to change?\n");
printf (" 1.Put one c,get one f. \n");
printf (" 2.Put form c1 to c2,get from f1 to f2. \n");
bar();
printf ("\n");
yc();
scanf ("%d",&c);
printf("\b");
there:if ( c == 1 )
coto();
else if ( c == 2)
csts();
else
{
ifw();
scanf("%d",&c);
goto there;
}
}
/*单温度转换*/
void foto(void)
{
float fahr;
printf ("Please put the fahr you want to change:");
scanf ("%f",&fahr);
printf ("\nThe fahr you want to change is:%.2f.\n" , fahr);
printf ("Thr celsisu changed out is:%.2f\n\n" , 5.0 * (fahr - 32.0) / 9.0 );
}
/*同上*/
void coto(void)
{
float celsisu;
printf ("Please put the celsisu you want to change:");
scanf ("%f",&celsisu);
printf ("\nThe celsisu you want ti change is:%.2f.\n" , celsisu);
printf ("The fahr change out is:%.2f.\n\n" , ((9.0*celsisu)+(32.0*5.0)) / 5.0);
}
/*多温度转换*/
void fsts(void)
{
float fahr1,fahr2,step,t;
printf ("Please put the frist fahr:");
scanf ("%f",&fahr1);
printf ("Please put the secend fahr:");
scanf ("%f",&fahr2);
printf ("Please put the step:"); /*输入连续的温度之间的间隔(比如1-100度~只看整十的度数`~间隔就是十)*/
scanf ("%f",&step);
if (fahr1 > fahr2) /*将输入的温度按由小到大排列*/
{
t = fahr1;
fahr1 = fahr2;
fahr2 = t;
}
printf ("\nFAHR1 CELSISU1\n\n");
for ( ; fahr1<=fahr2 ; fahr1 += step )
printf ( "%.2f %.2f\n" , fahr1, 5.0 * (fahr1-32.0) / 9.0);
printf ("\nFAHR2 CELSISU2\n");
}
/*同上*/
void csts(void)
{
float celsisu1,celsisu2,step,t;
printf ("Please put the frist celsisu:");
scanf ("%f",&celsisu1);
printf ("Please put the secend celsisu:");
scanf ("%f",&celsisu2);
printf ("Please put the step:");
scanf ("%f",&step);
if ( celsisu1>celsisu2 )
{
t=celsisu1;
celsisu1=celsisu2;
celsisu2=t;
}
printf ("\nCELSISU1 FAHR1\n\n");
for ( ; celsisu1 <= celsisu2 ; celsisu1 += step )
printf ( "%.2f %.2f\n" , celsisu1,((9.0 * celsisu1)+(32.0*5.0)) / 5.0);
printf ("\nCELSISU2 FAHR2\n");
}