Go to Void(s) from Menu system.

Hi! I was hoping if it were possible to go into a void from a do switch menu. I have already got the exiting game option to work, but I need some help on the other 3 options. Any help would be appreciated!

Game.cpp

#include <iostream>
#include <fstream>
#include <string>
#include "BlackJack.h"
#include "Hangman.h"
#include "Snake.h"
using namespace std;

#define TRUE 1
#define FALSE 0

//void BlackJack();
//void Hangman();
//void Snake();

int main()
{
int MenuRepeat;
int UserSelection;
int a, b, c;

MenuRepeat = TRUE;

do
{
cout << endl;
cout << "Welcome! Please pick one of the following options. \n1. Play BlackJack \n2. Play Hangman \n3. Play Snake \n4. Quit \nOption: ";
cin >> UserSelection;
cout << endl;

switch (UserSelection)
{

case 1: &blackjack::BlackJack;
break;
case 2: &hangman::Hangman;
break;
case 3: &snake::Snake;
break;
case 4: MenuRepeat = FALSE();
break;
default: cout << "Incorrect Option. Please either play one of the games or Quit." << endl;
break;
}
} while (UserSelection != 4);

return 0;
}

void blackjack::BlackJack()
{
cout << "Welcome to BlackJack!";
}

void hangman::Hangman()
{
cout << "Welcome to Hangman!";
}

void snake::Snake()
{
cout << "Welcome to Snake!";
}

BlackJack.h

#ifndef _BLACKJACK_H_
#define _BLACKJACK_H_

class blackjack
{
public:
void BlackJack();
};

#endif

Hangman.h

#ifndef _HANGMAN_H_
#define _HANGMAN_H_

class hangman
{
public:
void Hangman();
};

#endif

Snake.h

#ifndef _SNAKE_H_
#define _SNAKE_H_

class snake
{
public:
void Snake();
};

#endif
It is a big mess.
Please use code tags...
However:
1. MenuRepeat = FALSE(); should be MenuRepeat = FALSE;
2. Why
1
2
#define TRUE 1
#define FALSE 0 
? Why don't you use bool MenuRepeat and true/false?
3. You should initialize variables
4. while (UserSelection != 4) should be while (MenuRepeat)
5.
1
2
		case 1: &blackjack::BlackJack;
			break;
should be
1
2
3
4
5
6
			case 1:
		{
			blackjack bl;
			bl.BlackJack();
			break;
		}
and the same for the other options.
6. Don't you know constructors?
1
2
3
4
5
6
7
8
9
10
class blackjack
{
public:
	blackjack();
};

blackjack::blackjack()
{
	cout << "Welcome to BlackJack!";
}

and
1
2
3
4
5
		case 1:
		{
			blackjack bl;
			break;
		}

7. What is the purpose of int a, b, c;?
8. Did you see what happens if the user writes a non numeric text?
Right, the options now fall into the voids and read out the comments. The header files are the same.

This is just a basic menu to begin with. Hopefully, in time, I can expand on it. Also, I know I'm not very good at coding, but that's what websites like these are for, to learn from your mistakes. Thanks for the help you gave me!

Game.cpp

#include <iostream>
#include <fstream>
#include <string>
#include "BlackJack.h"
#include "Hangman.h"
#include "Snake.h"
using namespace std;

//#define TRUE 1
//#define FALSE 0

//void BlackJack();
//void Hangman();
//void Snake();

int main()
{
bool MenuRepeat = true;
int UserSelection;

//MenuRepeat = TRUE;

do
{
cout << endl;
cout << "Welcome! Please pick one of the following options. \n1. Play BlackJack \n2. Play Hangman \n3. Play Snake \n4. Quit \nOption: ";
cin >> UserSelection;
cout << endl;

switch (UserSelection)
{

case 1:
{
blackjack bl;
bl.BlackJack();
break;
}
case 2:
{
hangman hm;
hm.Hangman();
break;
}
case 3:
{
snake sk;
sk.Snake();
break;
}
case 4:
{
MenuRepeat = false;
break;
}
default:
{
cout << "Incorrect Option. Please either play one of the games or Quit." << endl;
break;
}
}
} while (MenuRepeat);

return 0;
}

void blackjack::BlackJack()
{
cout << "Welcome to BlackJack!";
system ("pause");
}

void hangman::Hangman()
{
cout << "Welcome to Hangman!";
system("pause");
}

void snake::Snake()
{
cout << "Welcome to Snake!";
system("pause");
}
Topic archived. No new replies allowed.