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, oneat 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; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.