void main()
{
float num3;
char char1,char2,char3;
clrscr();
for(;;)
{
clrscr();
printf(“a.货币转换\n”);
printf(“b.长度转换\n”);
printf(“c.退出\n”);
printf(“================================\n”);
printf(“你的选择是:\n”);
scanf(“\n%c”,&char2);
for (;;)
{
if (char2==’a'||char2==’b'||char2==’c')
break;
else
{
printf(“\n输入错误,请重新输入!\n”);
printf(“你的选择是:\n”);
scanf(“\n%c”,&char2);
}
}
switch(char2)
{
case ‘a’:
printf(“================================\n”);
printf(“a.美元转换为人民币\n”);
printf(“b.人民币转换为美元\n”);
printf(“c.退出\n”);
printf(“================================\n”);
printf(“你选择的转换方式是:\n”);
scanf(“\n%c”,&char3);
for (;;)
{
if (char3==’a'||char3==’b'||char3==’c')
break;
else
{
printf(“\n输入错误,请重新输入!\n”);
printf(“你的选择是:\n”);
scanf(“\n%c”,&char3);
}
}
switch(char3)
{
case ‘a’:
printf(“请输入需要转换的金额:\n”);
scanf(“\n%f”,&num3);
for (;;)
{
if (num3>=0)
break;
else
{
printf(“\n输入错误,请重新输入!\n”);
scanf(“\n%f”,&num3);
}
}
printf(“\n换算的结果是:%f元”,num3*8.278);
printf(“\n是否退出程序? y or n\n”);
scanf(“\n%c”,&char1);
switch(char1)
{
case ‘y’:
exit();
case ‘n’:
break;
}
getch();
break;
case ‘b’:
printf(“请输入需要转换的金额:\n”);
scanf(“\n%f”,&num3);
for (;;)
{
if (num3>=0)
break;
else
{
printf(“\n输入错误,请重新输入!\n”);
scanf(“\n%f”,&num3);
}
}
printf(“\n换算的结果是:%f元”,num3/8.278);
printf(“\n是否退出程序?y or n\n”);
scanf(“\n%c”,&char1);
switch(char1)
{
case ‘y’:
exit();
case ‘n’:
break;
}
getch();
break;
case ‘c’:
exit();
}
break;
case ‘b’:
printf(“================================\n”);
printf(“a.英尺转换为米\n”);
printf(“b.米转换为英尺\n”);
printf(“c.退出\n”);
printf(“================================\n”);
printf(“你的选择是:\n”);
scanf(“\n%c”,&char3);
for (;;)
{
if (char3==a||char3==b||char3==c)
break;
else
{
printf(“输入错误,请重新输入!\n”);
printf(“你的选择是:\n”);
scanf(“\n%c”,&char3);
}
}
switch(char3)
{
case ‘a’:
printf(“请输入需要转换的长度:\n”);
scanf(“\n%f”,&num3);
for (;;)
{
if (num3>=0)
break;
else
{
printf(“\n输入错误,请重新输入!\n”);
scanf(“\n%f”,&num3);
}
}
printf(“\n转换的结果是:%f米”,num3*0.3048);
printf(“\n是否退出程序?y or n\n”);
scanf(“\n%c”,&char1);
switch(char1)
{
case ‘y’:
exit();
case ‘n’:
break;
}
getch();
break;
case ‘b’:
printf(“请输入需要转换的长度:\n”);
scanf(“\n%f”,&num3);
for (;;)
{
if (num3>=0)
break;
else
{
printf(“\n输入错误,请重新输入!\n”);
scanf(“\n%f”,&num3);
}
}
printf(“\n转换的结果是:%f英尺”,num3/0.3048);
printf(“\n是否退出程序?y or n\n”);
scanf(“\n%c”,&char1);
switch(char1)
{
case ‘y’:
exit();
case ‘n’:
break;
}
}
case ‘c’:
exit();
}
}
}
>> 本文固定链接: http://www.vcgood.com/archives/2265
请大家帮帮忙!!谢谢了!
还有,如果我要按完一个后换另外一个的话要怎么弄?
例如:(“a.货币转换\n”);
(“b.长度转换\n”);
(“c.退出\n”);
(“================================\n”);
(“你的选择是:\n”);
如果我选了a后.怎么清了上面这个直接换去
(“================================\n”);
(“a.美元转换为人民币\n”);
(“b.人民币转换为美元\n”);
(“c.退出\n”);
(“================================\n”);
也就是整个屏幕只有上面这个?
高手帮帮我.
可以把要一直要显示的内容写成一个函数,然后,没一次要显示其它内容前调用此函数
上面的程序上有一错误,if 语句,的工a、b、c没有字符定界符