# its C++ programming can any one give me the solution?

• Feb 12th 2013, 04:45 PM
Riana
its C++ programming can any one give me the solution?
Drivers are concerned with the gasoline consumption by their automobiles. One driver has kept track of several full tanks of gasoline by recording kilometers driven and number of litters used for each full tank. Develop a program that will input the kilometers driven and number of litters of gasoline used for each full tank. After processing all input information, the program should calculate and print the combined average gasoline consumption for the vehicle. The user should enter y as long as he wants to continue the input.

(its c++.)
• Feb 12th 2013, 05:19 PM
HallsofIvy
Re: its C++ programming can any one give me the solution?
Surely you don't mean "input the kilometers driven and number of liters of gasoline used for each full tank". The number of liters per tank is not relevant. What is relevant is the total number of liters of gasoline used. Perhaps what you mean is "the number of full tanks". If you know how many liters there is in a tank (which is a constant) then multiplying that by the number of full tanks gives the number of liters of gasoline used. The "combined average gasoline consumption" is the total liters used divided by the distance driven.
• Feb 12th 2013, 05:37 PM
Riana
Re: its C++ programming can any one give me the solution?
can you please tell me the code for after i have entered the liter and kilometer number......its sentinel code i can't figure it out i have almost done it here it is but there is some mistake because of which its not working properly....please help me!

#include <iostream>
using namespace std;
int main(){
double L=0;
double Km=0;
double LL=0;
double Kmm=0;
char sentinel = 'y';
cout<<"Enter your number of liters :"<<endl<<endl;
cin>>L;
cout<<"Enter your number of kilometer :"<<endl<<endl;
cin>>Km;
while(L='y'){
LL=LL+L;
Kmm=Kmm+Km;
cout<<"Your car consumed" << Kmm/LL << "litre per 100Km"<<endl<<endl;
cout<<"Enter your number of litre or y to continue:"<<endl<<endl;
cin>>sentinel;}

return 0;}
• Feb 15th 2013, 03:11 PM
DavidB
Re: its C++ programming can any one give me the solution?
A few things caught my eye:

1) You prompt the user to enter litres and kilometers; however, your output statement outputs litres per 100 Km. Where did you do the conversion from km to 100 km?

2) You initialize the L variable to L = 0.
But then you input it anyhow, so you needn't have bothered initializing it.

3) The beginning of the while loop checks if L is equal to 'y', but you have accepted it as input as double. So which variable type is it? A char or a double?
And your comparison is not right. You should use '==' to check for equality. '=' is an assignment, so you are assigning L the value of 'y'.

4) Just before the end of the while loop, you prompt the user to enter number of litres or y to continue. But sentinel is a char variable type. You cannot use it as a double too.

5) You do not accept new values of L each time through the loop, so it never changes.