So I'm working on a code to program a Car Instrument Simulator and I'm supposed to have a switch statement for a menu to: Show gauges, ask how far they are to Driving, ask how much Gas to add, and to Exit. I got it to show the menu but when I press one of the options it doesn't do anything. I would like someone to help me to figure out what I'm missing and not saying to help me do it because I want to learn so next time I won't have the same problem, been working on it for a while now and even looked up some videos about switch statements but I'm just not getting it.
#include <iostream>
#include <string>
using namespace std;
void printmenu();
class FuelGauge
{
private:
int CurrentFuel;
public:
FuelGauge();
~FuelGauge();
FuelGauge(int g)
{
CurrentFuel = g;
}
int getCurrentFuel()
{
return CurrentFuel;
}
void IncrementFuel()
{
int gas;
cout << "How much fuel are you putting in? " << endl;
cin >> gas;
for (int fuel = gas; gas > 0; gas--) {
CurrentFuel++;
}
}
void DecrementFuel()
{
if (CurrentFuel > 0)
CurrentFuel--;
}
};
FuelGauge::FuelGauge()
{
}
FuelGauge::~FuelGauge()
{
}
class Odometer
{
private:
int CurrentMileage;
FuelGauge* fuel;
public:
Odometer();
~Odometer();
Odometer(int miles, FuelGauge* f)
{
CurrentMileage = miles;
fuel = f;
}
int getCurrentMileage()
{
return CurrentMileage;
}
void incrementCurrentMileage()
{
if (CurrentMileage < 999999)
CurrentMileage++;
else
CurrentMileage = 0;
}
void decrementCurrentMileage()
{
if (CurrentMileage > 24)
CurrentMileage--;
(*fuel).DecrementFuel();
}
};
Odometer::Odometer()
{
}
Odometer::~Odometer()
{
}
int main()
{
FuelGauge fuel(15);
Odometer odo(0, &fuel);
int n = 0;
while (n != 5) {
printmenu();
cin >> n;
switch (n) {
case 1:
fuel.getCurrentFuel();
break;
case 2:
odo.getCurrentMileage();
break;
case 3:
break;
case 4:
fuel.IncrementFuel();
break;
default:
break;
}
return 0;
}
}
void printmenu() {
cout << "1. Show current fuel " << endl;
cout << "2. Show current status of the odometer " << endl;
cout << "3. How far are you going? " << endl;
cout << "4. How much gass are you putting in? " << endl;
}