#include #include // for the "i/o manipulators" setw and setprecision #include using namespace std; int main() { double volume {0.0}; // Initialize volume variable cout << "What is the volume of petroleum in liters: "; cin >> volume; if (!cin) { cerr << "Sorry, that wasn't a number.\n"; return EXIT_FAILURE; } if (volume <= 0.0) { cerr << "Your input was less than the expected volume.\n"; return EXIT_FAILURE; } int trips {0}; cout << "What is the number of trips you want to make? "; cin >> trips; if (!cin) { cerr << "Sorry, that wasn't a number.\n"; return EXIT_FAILURE; } if (trips < 1) { cerr << "The number you typed in is less than the expected value.\n"; return EXIT_FAILURE; // Exit with failure if trips is less than 1 } if ( trips > 10) { cerr << "Sorry, we cannot accomodate more than 10 trips to mass.\n"; return EXIT_SUCCESS; } double rate; cout << "What is the rate at which you want to travel to mass? "; cin >> rate; if (!cin) { cerr << "Sorry, that wasn't a number.\n"; return EXIT_FAILURE; } if (rate <= 0) { cerr << "The rate of change can neither be zero nor negative.\n"; return EXIT_FAILURE; } // Output column headings cout << "trip volume\n" << "---- ------\n"; for (int trip {1}; trip <= 10; ++trip) { volume *= rate; // Reduce the volume based on the rate cout << " " << setw(2) << trip << " L" << fixed << setprecision(2) << volume << "\n"; } return EXIT_SUCCESS; }