0

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;
}
Dmitry Kuzminov
  • 6,180
  • 6
  • 18
  • 40
thly01
  • 1
  • 1
  • Did you press enter after you inputted the option? In most terminals the input isn't sent to your program until then. – eesiraed Nov 30 '19 at 04:37
  • Are you asking why nothing would happen in option 3? Also, are you asking why the menu shows once? Could you add an example input and output? –  Nov 30 '19 at 05:42
  • yes, I run the program it shows the menu and when I type in a number like 1 it shows up blank. – thly01 Dec 02 '19 at 00:18

1 Answers1

0

What do you plan to observe? You call some methods that return values without any side effects, and you don't do anything with those values: you get lost them immediately. You should probably output them:

cout << fuel.getCurrentFuel();
Dmitry Kuzminov
  • 6,180
  • 6
  • 18
  • 40