请关贴。。。作者: Koo01 时间: 2014-7-31 08:58 AM
哇!好难哦……
我之前做过calendar的,现在忘光光了作者: edison31 时间: 2014-7-31 09:24 AM
在你diplay result后加while(1);
就会出现你的result了,不然他会直接end,或者你做给他显示“press any key to leave",这样他就不会直接end了。还有你的function都已经错了,下面的图片是你code的result。这类型code应该只是属于a-level或foundation的assignment罢了,很容易罢了的,你应该要学会如何debug他。
// when 6th impact,height > final height,impact ++ to 7,and now the height < final height,then no more impact++.
} while(height_earth<=0 || height_earth<final_height );作者: memring007 时间: 2014-7-31 11:33 AM
你的nitial_h也没有变数啊。如果有assign value给它就可以。
if (moon_h < final_h)
moon_count = impact;
}while(moon_h >= final_h);
cout<<"On Earth, it takes " <<earth_count <<" bounces to reach below the final height" <<endl;
cout<<"On Moon, it takes " <<moon_count <<" bounces to reach below the final height" <<endl;
}
int main()
{
float initial_h;
int impact=0, count=0;
int earth_count=0,moon_count=0;
float impact_speed_e=0,impact_speed_m=0,earth_h,moon_h;
float final_h;
do
{
cout<<"Enter Initial Height: ";
cin>>initial_h;
cout<<"Enter Final Height: ";
cin>>final_h;
if (initial_h == 0 && final_h == 0)
cout<<"Initial Height and Final Height cannot be 0";
else if (initial_h == 0)
cout<<"Initial Height cannot be 0";
else if (final_h == 0)
cout<<"Final Height cannot be 0";
cout<< endl << endl;
} while(initial_h == 0 || final_h == 0);
cout<<"\t\t On Earth \t\t\t\t On Moon" << endl;
cout<<"Impact \t Impact Speed \t Height \t\t Impact Speed \t Height" <<endl;