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

Write a program that declares three one-dimensional arrays named miles, gallons,

ID: 3620512 • Letter: W

Question

Write a program that declares three one-dimensional arrays named miles, gallons, and mpg. Each array should be capable of holding 10 elements. In the miles array, store the numbers 240.5, 300.0, 189.6, 310.6, 280.7, 216.9, 199.4, 160.3, 177.4, and 192.3. In the gallons array, store the numbers 10.3, 15.6, 8.7, 14, 16.3, 15.7, 14.9, 10.7, 8.3, and 8.4. Each element of the mpg array should be calculated as the corresponding element of the miles array divided by the equivalent element of the gallons arrays: for example, mpg[0] =miles[0]/gallons[0]. Use pointers when calculating and displaying the elements of the mpg array.

Explanation / Answer

I had to fix a couple things, now it outputs all the average mpg's







#include <iostream>

using namespace std;

int main()
{
double miles[10]={240.5,300.0,189.6,310.6,280.7,216.9,199.4,160.3,177.4,192.3};

double gallons[10]={10.3,15.6,8.7,14.0,16.3,15.7,14.9,10.7,8.3,8.4};



double mpg[10];

mpg[0]=miles[0]/gallons[0];

mpg[1]=miles[1] /gallons[1];

mpg[2]=miles[2] /gallons[2];

mpg[3]=miles[3] /gallons[3];

mpg[4]=miles[4] /gallons[4];

mpg[5]=miles[5] /gallons[5];

mpg[6]=miles[6] /gallons[6];

mpg[7]=miles[7] /gallons[7];

mpg[8]=miles[8] /gallons[8];

mpg[9]=miles[9] /gallons[9];





for (int i=0;i<10;i++){

cout << mpg[i] <<endl;

};

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote