Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

problem: While loops with multi-conditions

$
0
0
The program got stuck at these "while" loops, I tried many forms but still can't run.

#include <iostream>
using namespace std;

// Function of reverse
class Odometer
{ 
public:

	void odometer()
	{	
		milesDriven = 0;
		Mpg = 0;
		Igallons=0;
	}

	void fuelleft(double gallonsleft)
	{
		gallonsleft = Igallons - milesDriven / Mpg;
	}

	void Imiles(double milesD)
	{
		milesDriven = milesD + milesDriven;
	}

	void Odometer::set_mpg(double mpg)
	{
		mpg = Mpg;
	}

	void Odometer::set_gallons(double gallons)
	{
		gallons = Igallons;
	}
	

private:
	double milesDriven;
	double Mpg;
	double Igallons;	

};


int main()
{
	Odometer CarOdometer;
	double milesdriven = 0;
	double MPG=5;
	double Gallons=10;
	double Gallonsleft=0;

	while (( Gallons >= 10 ) && ( Gallons <= 30))
	{
		cout << "Enter gallons in tank (10-30): " << endl;
		cin >> Gallons;
		if (Gallons <10 || Gallons > 30)
			cout << "Error: "<< endl;
	}
		CarOdometer.set_gallons(Gallons);


	while ((MPG >= 5) && (MPG <= 70))
	{
	cout << "Enter Fuel efficiency (MPG) (5-70): " << endl;
	cin >> MPG;
	if (MPG <5 || MPG > 70)
		cout << "Error: "<< endl;
	}
		CarOdometer.set_mpg(MPG);

	while (milesdriven = -1)
	{
		cout << "Enter miles for trip (-1 to finish, no more trips) : " << endl;
		cin >> milesdriven;

		CarOdometer.Imiles(milesdriven);
	}

	CarOdometer.fuelleft(Gallonsleft);
	cout << "Gallons left in the tank: "<< Gallonsleft <<" gallons" << endl; 


	return 0;
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>