i found my thinking in this program is totally wrong (but i still want to know what cause this run error)
---------------
Hey guys, so I was drafting a simple program on miles per gallon.
Disregard this draft, I had a problem when I tried to run the program.
I used Dev c++, and I can compiled the program.
But when I press ctrl + f10 to run the program, it said gallon.exe has encountered a problem....
just like the screenshot i took.
what is the problem? here is my code.
// Miles per gallon program
// Written in C++
#include <iostream>
using namespace std;
int main()
{
// assign the type
int gallon, // gallon used
miles, // miles used
totalMiles, // total miles driven
totalGallon; // total gallon used
float mpg; // miles per gallon
// initialization
totalMiles = 0;
totalGallon = 0;
mpg = 0;
//formula
mpg = totalMiles / totalGallon;
// let us get a welcome message first
cout << "Welcome to Driver Mile Per Gallon Program! A simple and an easy use program to find out mile per gallon for your tankful!\n" <<endl;
cout << "Please follow the guideline to operate the program properly:\n" <<endl;
cout << "[1] Enter any positive value for each input.\n" <<endl;
cout << "[2] Enter -1 to end this program and will print the mile per gallon result at the end of the program.\n" <<endl;
// now let us begin our program
while (miles && gallon != -1) {
cout << "Enter the mile driven:\n";
cin >> miles;
cout << "Enter the gallon used:\n";
cin >> gallon;
totalMiles = totalMiles + miles;
totalGallon = totalGallon + gallon;
}
// how to find the mile per gallon
if (miles && gallon != -1) {
cout << "Your Mile Per Gallon is: " << mpg << "\n";
}
else
cout << "You did not enter any value!\n" <<endl;
return 0;
}


Sign In
Create Account



Back to top









