C++怎么让这段程序循环执行??
#include<iostream.h>voidmain(){floata,b,c;cout<<"Enterthegallonsused(-1toend):";cin>>...
#include<iostream.h>
void main()
{
float a,b,c;
cout<<"Enter the gallons used (-1 to end ):";
cin>>a;
if(a==-1)
cout<<"The overall average Miles/Gallon was 21.601423";
else
cout<<"Enter the miles driven:";
cin>>b;
c=b/a;
cout<<"The MIles / Gallon for this tank was "<<c<<endl;
}
初学C++, 这段代码怎么让它循环执行啊? 就是输出结果后程序不结束,又重新从第一条开始执行输入A的值? 展开
void main()
{
float a,b,c;
cout<<"Enter the gallons used (-1 to end ):";
cin>>a;
if(a==-1)
cout<<"The overall average Miles/Gallon was 21.601423";
else
cout<<"Enter the miles driven:";
cin>>b;
c=b/a;
cout<<"The MIles / Gallon for this tank was "<<c<<endl;
}
初学C++, 这段代码怎么让它循环执行啊? 就是输出结果后程序不结束,又重新从第一条开始执行输入A的值? 展开
3个回答
推荐于2018-03-10
展开全部
#include<iostream.h>
void main()
{
while(1)
{
float a,b,c;
cout<<"Enter the gallons used (-1 to end ):";
cin>>a;
if(a==-1)
cout<<"The overall average Miles/Gallon was 21.601423";
else
cout<<"Enter the miles driven:";
cin>>b;
c=b/a;
cout<<"The MIles / Gallon for this tank was "<<c<<endl;
}
}不过这样的死循环哦,就是一直循环不停的意思,如果需要其他功能以后再跟我说
void main()
{
while(1)
{
float a,b,c;
cout<<"Enter the gallons used (-1 to end ):";
cin>>a;
if(a==-1)
cout<<"The overall average Miles/Gallon was 21.601423";
else
cout<<"Enter the miles driven:";
cin>>b;
c=b/a;
cout<<"The MIles / Gallon for this tank was "<<c<<endl;
}
}不过这样的死循环哦,就是一直循环不停的意思,如果需要其他功能以后再跟我说
2013-12-24
展开全部
一般在外面加个while(1){}就可以了!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-12-24
展开全部
while(1){写你的代码}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询