hello, I just had a quick question on my program. I'm trying to perform an elevator class program to simulate an elevator that has 3 stops. The only problem is that I can't figure out how my floors increase or decrease, it just increases by one.
Here is my code:
#include <iostream>
#include <iomanip>
using namespace std;
class elevator
{
public:
elevator();
void ElevatorMotion();
int currentFloorNum;
};
int main()
{
elevator e;
int ans;
cout << "Welcome to the Elevator System";
cout << "\nYou are on the 1st Floor";
do
{
cout << "Would You Like to Go up (press 1)" << endl
<< "or down (press 2) A Floor?" << endl
<< "(-1 to exit after choice input) " << endl;
cin >> ans;
if(ans == -1)
break;
if(ans == 4)
cout << "There is no Fourth Floor, Please Choose a Valid Floor" << endl;
e.ElevatorMotion();
}while(ans != -1);
}
elevator::elevator()
{
currentFloorNum = 1;
}
void elevator::ElevatorMotion()
{
bool goingUp = true;
bool goingDown = false;
int currentFloorNum = 1;
int nextFloor;
if(goingUp == true)
{
nextFloor = currentFloorNum + 1;
currentFloorNum = currentFloorNum + nextFloor;
currentFloorNum = nextFloor;
}
else
nextFloor = currentFloorNum - 1;
currentFloorNum = currentFloorNum + nextFloor;
currentFloorNum = nextFloor;
cout << "You are on the " << currentFloorNum << " floor" << endl;
}
should I use a for loop in ElevatorMotion function, I'm trying to differentiate the bool values, when I run my program it just increases by one and stays that way