以下是我写的代码,总觉得有些繁琐,有没有更好的方法来解这个问题呢。本人新手,请各位多多指教。
代码: 全选
#include <iostream>
using namespace std;
int main()
{
const double ton=35273.92;
double weight;
int amount;
while(1)
{
cout<<"please input the weight (ounce)of per cornmeal: ";
cin>>weight;
if (weight>0)
{
amount=ton/weight;
if (amount<1)
cout<<"the number you input is to large\n";
else
{
cout<<"each cornmeal has "<<weight/ton<<" ton"<<endl;
cout<<"you need "<<amount<<" to get 1 ton\n";
}
}
else
cout<<"error,please input a number larger than zero\n";
}
return 0;
}