Answer:
The c++ program for the given scenario is shown below.
#include <iostream>
using namespace std;
int main() {
// value is mentioned in the question
const int QUARTS_IN_GALLON = 4;
// any positive integer value can be assigned
int quartsNeeded = 25;
int gallons, quarts;
// 0 will be assigned if quartsNeeded is less than QUARTS_IN_GALLON
gallons = quartsNeeded/QUARTS_IN_GALLON;
// 0 will be assigned if quartsNeeded is completely divisible by QUARTS_IN_GALLON
quarts = quartsNeeded%QUARTS_IN_GALLON;
cout << "A job that needs " << quartsNeeded << " quarts requires " << gallons << " gallons plus " << quarts << " quarts." << endl;
return 0;
}
OUTPUT
A job that needs 25 quarts requires 6 gallons plus 1 quarts.
Step-by-step explanation:
This program is not designed to take any input from the user and hence, no validation is implemented.
1. A constant integer variable is declared to hold the number of quarts present in a gallon of paint.
const int QUARTS_IN_GALLON = 4;
2. An integer variable is declared to hold the quarts of paint needed for the job. This variable is initialized inside the program.
int quartsNeeded = 25;
3. Two integer variables are declared to hold the number of gallons and quarts calculated from the variables declared and initialized previously.
4. The number of gallons is computed as shown. Since gallon variable is an integer variable, it will store only the integer part of the result.
gallons = quartsNeeded/QUARTS_IN_GALLON;
If there is no remainder for the above expression, the variable quarts will be assigned 0. Hence, no validation is required for this.
5. The number of quarts is computed as shown. Since quarts variable is an integer variable, it will store only the integer part of the result.
quarts = quartsNeeded%QUARTS_IN_GALLON;
If there is no remainder for the above expression, the variable quarts will be assigned 0. Hence, no validation is required for this.
6. Lastly, display the message informing the number of gallons and quarts needed in all.
7. The program ends with a return statement.