C++ Noob question

Hi, I am new to C++ and i've caught myself stuck on my first project.

I am trying to make a game that has 5 pumps which you can turn on or off. I seem to have hit a blank wall with what I need to do next. I have been coding for a few days so please point me in the right direction.

I am looking to make a simple menu where the user is able to turn the pump on or off manually and the user is able to view the state of each up (weather is it on or off)

1
2
3
4
5
6
7
  struct pumpState{

	bool pumpReady = true;
	bool pumpStandby = false;

	string pumpState, pumpOne, pumpTwo, pumpThree, pumpFour, pumpFive;
};
Hi,

you cant name your string pumpState, its already been taken by your struct,

instead of making 2 bools you may just make one bool like bool state, then make it true/false according to your needs

PS: welcome to cplusplus.com
Your use of two bools seems to imply that a pump can have more that two states. If that is the case, you might want to consider an enum:
1
2
3
  enum pumpState { pumpStandby, pumpReady, pumpPumping };
...
  pumpState pumpOne = pumpStandby, pumpTwo = pumpStandby, pumpThree = pumpStandby, pumpFour = pumpStandby, pumpFive = pumpStandby;

enums are handy when an object can have more than two states.

I see enum is what I was looking for thank you. Also how am i able to let the user change the state of each pump? I have this so far but i'm not sure if it is right. Thanks for your help.
(the cout statements are not completed yet so please forgive the messiness of it.)


1
2
3
4
5
6
7
8
9
10
11
12
13
if (option == 1)
		{
			system("cls");
			cout << "State Of The Pumps" << endl;

			cout << "Pump 1  " << pumpOne << endl;
			cout << "Pump 2  " << pumpTwo << endl;
			cout << "Pump 3  " << pumpThree << endl;
			cout << "Pump 4  " << pumpFour << endl;
			cout << "Pump 5  " << pumpFive << endl;
			system("pause");
			cin >> option;
		}
Lines 6-10 are going to output the numeric value of the enum.

You probably want something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>
using namespace std;

enum pumpState { pumpStandby, pumpReady, pumpPumping };
const string stateNames[] = { "Standby", "Ready", "Pumping" };
const int MAX_PUMPS = 5;

pumpState pumps[MAX_PUMPS];

void displayPumpStates (pumpState pumps[])
{   system("cls");
	cout << "State Of The Pumps" << endl;

    for (int i=0; i<MAX_PUMPS; i++)
        cout << "Pump " << i << ": " << stateNames[pumps[i]] << endl; 
	system("pause");
}


how am i able to let the user change the state of each pump?

Not sure if you've learned classes yet. Each pump should be an instance of a Pump class.
pumpState is a member variable of your Pump class. Your Pump class should have functions such as RemoveNozzle() (changes state from ready to pumping) and ReplaceNozzle() (returns state to standby), etc.

Topic archived. No new replies allowed.