fork download
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int mile=0;
  6. int gallon=0;
  7. int TM=0; //total mile
  8. int TG=0; //total gallon
  9. double MPG=0;
  10. double Total=0;
  11. cout<<"Enter miles driven (-1 to quit):"<<mile<<endl<<"Enter gallons used:"<<gallon<<endl;
  12. while(mile!=0)
  13. {
  14. cin>>mile>>gallon;
  15. MPG=mile/gallon;
  16. TM=TM+mile;
  17. TG=TG+gallon;
  18. Total=TM/TG;
  19. cout<<"MPG this trip:"<<MPG<<endl<<"Total MPG:"<<Total<<endl;
  20. }
  21. return 0;
  22. }
  23.  
  24.  
Success #stdin #stdout 0.01s 5396KB
stdin
200 25
stdout
Enter miles driven (-1 to quit):0
Enter gallons used:0