插入一段这样的
printf("continue?Y/N\n")
fflush(stdin)//清空缓冲区
char ch=getchar()
if(ch=='Y'||ch=='y')
continue
break
前提是程序在大循环之中,若不是可以这样
do
{
......//你的程序代码放这边
printf("continue?Y/N\n")
fflush(stdin)
char ch=getchar()
}while(ch=='y'||ch=='Y')
最简单的形式#include<stdio.h>
void main()
{
char answer
do
{
//相关内容
//判断是否继续
printf("是否继续? (Y/N)")
fflush(stdin)
scanf("%c",&answer)
}while(answer=='Y')
}
#include <stdio.h>double jiafa(double x,double y)
double jianfa(double x,double y)
double chengfa(double x,double y)
double chufa(double x,double y)
int main()
{
double a
double b
char ch
for()
{
printf("请输入你的运算式:\n")
scanf("%lf%c%lf",&a,&ch,&b)
switch(ch)
{
case'+':
printf("运算结果为:%.2lf\n",jiafa(a,b))
break
case'-':
printf("运算结果为:%.2lf\n",jianfa(a,b))
break
case'*':
printf("运算结果为:%.2lf\n",chengfa(a,b))
break
case'/':
printf("运算结果为:%.2lf\n",chufa(a,b))
break
default :printf("符号输入错误!")
}
printf("请问是否要继续(y:是,n:否):\n")
{
fflush(stdin)
char ch='y'
char x
scanf("%c",&x)
if(x=='y')
{
system("cls")
continue
}
else
break
}
}
return 0
}
double jiafa(double x,double y)
{double z
z=x+y
return z
}
double jianfa(double x,double y)
{double z
z=x-y
return z
}
double chengfa(double x,double y)
{double z
z=x*y
return z
}
double chufa(double x,double y)
{double z
if(y==0)
{ printf("错误!除数不能为零!\n")
z=0}
else
z=x/y
return z
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)