Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a. Write, compile, and run a C++ program that accepts five values of gallons, on

ID: 3646012 • Letter: A

Question

a. Write, compile, and run a C++ program that accepts five values of gallons, one
at a time, and converts each value entered to its liter equivalent before the next value is
requested. Use a for loop in your program. There are 3.785 liters in 1 gallon of liquid.

#include<iostream>
using namespace std;
int main()
{
int gallon,conversions;
for(int i=0; i<5; i++)
{
cout << " Enter number of conversions: ";
cin >> conversions;

cout << " Enter number of gallons: ";
cin >> gallon;
cout <<"Liter equivalent : " << 3.785 * static_cast<float> (gallon) << endl;
}

system ("pause");
return 0;
}

b. Modify the program written for exercise (a.) to request the number of data items to be entered and converted first.

Explanation / Answer

#include using namespace std; int main() { int gallon,conversions,dataitems; coutdataitems; for(int i=0; i conversions; cout > gallon; cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote