首页 > 代码库 > mile for gallon 汽车省油
mile for gallon 汽车省油
计算汽车省油,用英里每加仑比较,允许重复比较
//mile for gallon 汽车省油 #include<iostream> const double GALLON = 0.264179; double milepergallon(double kilo,double mile); int main() { using namespace std; double kilo[2],mile[2],milebygallon[2]; char ans; do { cout<<"Enter the kilo and the mile of number first:\n"; cin>>kilo[0]>>mile[0]; cout<<"Enter the kilo and the mile of number second:\n"; cin>>kilo[1]>>mile[1]; milebygallon[0] = milepergallon(kilo[0],mile[0]); milebygallon[1] = milepergallon(kilo[1],mile[1]); cout<<"The first result is "<<milebygallon[0]<<" mile/gallon.\n"; cout<<"The second result is "<<milebygallon[1]<<" mile/gallon.\n"; if(milebygallon[0] > milebygallon[1]) cout<<"The first car fuel saving!"<<endl; else if(milebygallon[0] < milebygallon[1]) cout<<"The second car fuel saving!"<<endl; else cout<<"The two cat are same saving oil!"<<endl; cout<<"Do you want again?"; cin>>ans; }while(‘y‘ == ans || ‘Y‘ ==ans); return 0; } double milepergallon(double kilo,double mile) { double gallon; gallon = kilo * GALLON; return (mile / gallon); }
结果:
Enter the kilo and the mile of number first: 1 0.264179 Enter the kilo and the mile of number second: 1 0.264179 The first result is 1 mile/gallon. The second result is 1 mile/gallon. The two cat are same saving oil! Do you want again?y Enter the kilo and the mile of number first: 1 1 Enter the kilo and the mile of number second: 10 2 The first result is 3.78531 mile/gallon. The second result is 0.757062 mile/gallon. The first car fuel saving! Do you want again?y Enter the kilo and the mile of number first: 1 1 Enter the kilo and the mile of number second: 2 2 The first result is 3.78531 mile/gallon. The second result is 3.78531 mile/gallon. The two cat are same saving oil! Do you want again?
mile for gallon 汽车省油
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。