Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
1.1k views
in Computer by (69.4k points)

Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tanks of CNG by recording the miles driven and the gallons used for each tank.

Develop a C++ program that will input the kilometers driven and gallons used for each tank. The program should calculate and display the kilometers per gallon obtained for each tank of gasoline. After processing all input information, the program should calculate and print the average kilometers per gallon obtained for all tanks.

  • Formulate the algorithm as flowchart.
  • Write a C++ program as instructed.
  • Test, debug, and execute the C++ program.

1 Answer

+1 vote
by (64.1k points)
selected by
 
Best answer

#include<iostream.h>

#include<conio.h>

void main() {

clrscr();

int tanks=0;

float tot_km; float avg_k_p_g;

cout<<"Enter how many tanks filled :";

cin>>tanks;

float *kms=new float[tanks];

float *gallons_used=new float[tanks];

float *k_p_g=new float[tanks];

for(int i=0;i<tanks;i++)

{

cout<<"Enter how much kilometers covered for tank "<<i+1<<" ";

cin>>kms[i];

cout<<"Enter how much gallon used from tank "<<i+1<<" ";

cin>>gallons_used[i];

k_p_g[i]=kms[i]/gallons_used[i];

cout<<"KMs per Gallon obtained for tank No. "<<i+1<<" "<<k_p_g[i]<<endl;

tot_km+=k_p_g[i];

cout<<endl;

}

avg_k_p_g=tot_km/tanks;

cout<<"Average kilometers per gallon obtained for all tanks is "<<avg_k_p_g;

getch();

}

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...