Blackjack game

I've started to write the beginning of the game blackjack, this is just a menu, but I keep getting errors and I don't understand why? Could someone help, thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  
#include "pch.h"
#include <iostream>
using namespace std;

enum Suits {HEAT, DIAMOND, CLUB, SPADE};

char Menuchoice;

void Menu();
void NewGame();
void Help();
void About();
void Exit();


int main()
{
	Menu();
}

void Menu()
{
	do
	{
		cout << "Welcome to Blackjack" << endl;
		cout << "1. New Game - Press N" << endl;
		cout << "2. Help - Press H" << endl;
		cout << "3. About - Press A" << endl;
		cout << "4. Exit - Press X" << endl;

		cin >> Menuchoice;

		if (Menuchoice == 'N')
		{
			NewGame();
		}

		if (Menuchoice == 'H')
		{
			Help();

		}

		if (Menuchoice == 'A')
		{
			About();
		}

		else if (Menuchoice == 'X')
		{
			Exit();
		}
		else {
			cout << "Oops wrong letter, please try again" << endl;
		}


	} while (Menuchoice != 'X');

}

void About()
{
	cout << "Blackjack" << endl;

}
I keep getting errors

Fix them.
UPDATE: So, I've fixed the errors but whenever I pick an option it always displays "Oops wrong letter, please try again" but I only want that if the user picks neither of the options above.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "pch.h"
#include <iostream>
using namespace std;

enum Suits {HEAT, DIAMOND, CLUB, SPADE};

char Menuchoice;

void Menu();
void NewGame();
void Help();
void About();
void Exit();


int main()
{
	Menu();
}

void Menu()
{
	do
	{
		cout << "Welcome to Blackjack" << endl;
		cout << "1. New Game - Press N" << endl;
		cout << "2. Help - Press H" << endl;
		cout << "3. About - Press A" << endl;
		cout << "4. Exit - Press X" << endl;

		cin >> Menuchoice;

		if (Menuchoice == 'N')
		{
			NewGame();
		}

		if (Menuchoice == 'H')
		{
			Help();

		}

		if (Menuchoice == 'A')
		{
			About();
		}

		else if (Menuchoice == 'X')
		{
			Exit();
		}
		else {
			cout << "Oops wrong letter, please try again" << endl;
		}


	} while (Menuchoice != 'X');

}

void NewGame()
{
	cout << "New Game selected" << endl;
}



void Help()

{
	cout << "help " << endl;
}

void About()
{
	cout << "Blackjack" << endl;

}

void Exit()
{
	cout << "Exiting.." << endl;
}
Last edited on
Some of your if's should be else if's. For example the 'N' case: if you chose this then its if block would run; then you would go to the next if statement and have to pass through the catch-all else block.

You haven't written definitions of some of the functions. Put some placeholders in if you don't want to write them just yet.

Your options must all be entered in upper case. Either use toupper() on Menuchoice, or give upper- and lower-case alternatives in your if statements.

Get rid of this dratted pch.h garbage; then it would run as-is in c++ shell.
Last edited on
But if I change the N statement to else if it won't run
But if I change the N statement to else if it won't run

I didn't say that first one ... change the ones underneath!!!

pseudo-code
IF (N case)          // this is the only "pure" IF
...
ELSE IF ( another case )
...
ELSE IF ( yet another case )
...
ELSE      // if none of the above worked
...
END IF        // phew!
Last edited on
Yeah I just realised what you meant sorry
Topic archived. No new replies allowed.