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;elsecout<<"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?轉載于:https://blog.51cto.com/9320314/1546778
總結
以上是生活随笔為你收集整理的mile for gallon 汽车省油的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [1197]约瑟夫问题 (循环链表)SD
- 下一篇: 莫名其妙的主机名 VM_32_234_c