My Program will not compile

I have been assigned to create a program for a mini casino where the user start with twenty dollars and can bet on multiple games such as Flip the coin, Guess the Number, Street Crabs, and BlackJack.

This project is so big and exhaustive and now I have done everything I think I can do but the program will not even compile so I can not even see what is going wrong with my program.
The only Errors that I can see are in the lines of void shuffleCards()



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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
std::vector<std::string> suits { "C", "D", "H", "S" };

    here { has a red squiggle that says " expected a ;"

and

  unshuffled.push_back (std :: to_string(val) + suits[s]);

       where std says " more than one instance of overloaded function " std :: to_string" matches the arguments list.


Although shuffleCards() is a function my professor gave me so I would think that was the problem.

This is what I have.

#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
using namespace std;

//////////////////////////////////////////////
//	Functionality I have provided for you		//
//////////////////////////////////////////////
std::vector<std::string> _cards;
void displayMenu();
void shuffleCards();
void printCards();
int getCardValue(std::string card);
std::string getSuit(std::string card);
std::string drawCard();
///////////////////////////////////////////END
////////////////////////////////////////////

//////////////////////////////////////////////
// Functionality you need to provide				//
//////////////////////////////////////////////
// basic casino functionality
void seedRand(int seed);
void printMoney(double money);
void printWallet(double wallet);
void payMoney(double & wallet, double amount);
void winMoney(double & wallet, double amount);
int getRandomNumber(int min, int max);
double placeBet(double & wallet);
// games
void playFlipTheCoin(double & wallet);
void playGuessTheNumber(double & wallet);
void playStreetCraps(double & wallet);
void playBlackjack(double & wallet);
///////////////////////////////////////////END
//////////////////////////////////////////////



  void seedRand()
  {
	 srand(time(0));
  }

  void printMoney (double money)
  {
	  cout << "$" << setprecision(2) << fixed; 
  }

  void printWallet (double wallet)
  {
	  cout << "Wallet: "<< " " << printMoney;
  }
  void payMoney (double & wallet, double money)
  {
	  cout << wallet; 
	  wallet -= money;
	  cout << " You Paid " << " " << money << "\n";
	  cout << wallet;
  }

  void winMoney ( double & wallet, double money)
  {
	  cout << wallet;
	  wallet += money;
	  cout << "You just won" << " " << money << "\n";
	  cout << wallet;
  }

  int getRandomNumber(int min, int max)
  {
	  int r = getRandomNumber(min, max);

      std::cout << r << "\n";

      return r;

	  
  }

  double placeBet(double & wallet)
  {
	  cout << " How much do you want to bet" << "\n";
	  cin >> wallet >> "\n";
	  - wallet;
	  double bet = placeBet(wallet);
	  cout << payMoney << "\n";
	  cout << "Your original bet was " << " " << bet;
  }











int main()
{
  // You need money to spend on the games
  double wallet = 20.00;

  // Here is where you should begin writing your code.
  // The first thing you need to do is call seedRand.
  // After that, create your loop. Inside of your loop,
  //  call my displayMenu function and act on the user's
  //  input.
  // Write some code here
 
  
  seedRand();

  displayMenu();
char gameSelection;
cin >> gameSelection;


switch (gameSelection)

{


case 'F':

case 'f':

playFlipTheCoin(wallet);

case 'G':

case 'g':

playGuessTheNumber(wallet);

case 'S':

case 's':

playStreetCraps(wallet);

case 'B':

case 'b':

playBlackjack(wallet);

break;

case 'X':

case 'x':

break;

default:

cout << " Invalid Selection! \n";
displayMenu();
break;

}
  // Here's courtesy code to stop the window from closing.
  std::cout << "Press ENTER to continue";
  std::cin.ignore();
  std::cin.get();

}








void playFlipTheCoin (double & wallet)
{

	cout << " Welcome to the flip a coin game!" << "\n";
	payMoney (wallet, .50);
	cout << " Guess (H)eads or (T)ails!" << " ";
	char coinguess;
	cin >> coinguess;
	cout << "\n";

	int RanNum = getRandomNumber (1,2);
	int coinface;
	int head;
	int tails;
	if (RanNum == 1)
		coinface == head;
    if (RanNum == 2)
		coinface == tails;


	switch (coinguess)
	{
		case 'H':
		case 'h':
			{if (coinface == head)
				{cout << "The coin landed on heads";
			cout << " \n You guessed heads thats right!";
			winMoney(wallet, 1.00);
			cout << " \n You just won a $1.00";}
			if (coinface == tails)
				{cout << "The coin landed on Tails";
			cout << " \n You guessed heads you're wrong....haha";} }
		case 'T':
		case 't':
			if (coinface == tails)
				{cout << "The coin landed on tails";
			cout << " \n You guessed tails thats right!";
			winMoney(wallet, 1.00);
			cout << " \n You just won a $1.00";}
			if (coinface == head)
				{cout << "The coin landed on Heads";
			cout << " \n You guessed tails you're wrong....haha"; }

		

}
}


void playGuessTheNumber (double & wallet)
{


	while(true) { // Main loop.
		// Initialize and allocate.
		int number = getRandomNumber(1,100);
		int guess; // User guess is stored in here.
		int tries = 0; // Number of tries is stored here.
		char answer;

		cout << "Welcome to the Guess a number game";
		payMoney (wallet, 1.00);
		
		
		while(true) { // Get user number loop.
			// Get number.
			std::cout << "I have may sercet number. \n Enter a number between 1 and 100 (" << 10 - tries << " tries left): ";
			std::cin >> guess;
			std::cin.ignore();
			
			// Check is tries are taken up.
			if(tries >= 10) {
				break;
			}
			
			// Check number.
			if(guess > number) {
				std::cout << "Too high! Try again.\n";
			} else if(guess < number) {
				std::cout << "Too low! Try again.\n";
			} else {
				break;
			}
			
			// If not number, increment tries.
			tries++;
		}
		
		// Check for tries.
		if(tries >= 10) {
			std::cout << "You ran out of tries!\n\n";
		} else {
			// Or, user won.
			std::cout<<"Congratulations!! " << std::endl;
			std::cout<<"You just won $2.00 \n";
			winMoney(wallet,2.00);
		}

		}


}
void playStreetCraps (double & wallet) 
{
	int diceroll();
	cout << "Welcome to street craps";
	 printWallet ( wallet);
	 placeBet ( wallet );

	  int diceroll();
	 {
		 int die1 = getRandomNumber (1,6);
		 int die2 = getRandomNumber (1,6);
		 int sum = die1+ die2;

		 cout << " You rolled " << die1 << "+" << die2 << "=" << sum << endl;	 
	 }
	
	 enum status { CONTINUE , WON , LOST};

	 int point;
	 status gameStatus;
	 int dicesum = diceroll();

	 switch (dicesum)
	 {
	 case 7:
	 case 11:
		 gameStatus = WON;
		 break;
	 case 2:
	 case 3:
	 case 12:
		 gameStatus = LOST;
		 break;
	 default:
		 gameStatus = CONTINUE;
		 point = dicesum;
		 cout << " Point is" << point << endl;
		 break;
	 }

	 while (gameStatus = CONTINUE)
	 {
		 dicesum = diceroll();
		 if(dicesum == point)
			 gameStatus = WON;
		 else
			 if(dicesum == 7)
				 gameStatus = LOST;
	 }

	 if (gameStatus == WON )
	  {cout << "You Win!";
	  winMoney (wallet, 2*placeBet(wallet) );
	  
	 }
	 else
		 cout << "You lose! HaHa!" << endl;

	
	 } 






I had to cut off half of the code because of the character limit I'll post the other on a different question.
Last edited on
Hi and welcome to cpluplus :+),

Just a friendly reminder about a few things to start off with :+)

Ok, first up - always please use code tags:

http://www.cplusplus.com/articles/z13hAqkS/


You can edit your code by pressing the <> button on the format menu.

Next, if yo have lots of code, make two posts - not two topics. Multiple topics are a problem because there will be replies to both - often saying the same things, which ultimately wastes people's time. So I suggest making a post in the other topic, directing people to reply to this topic, with a link to this one.

Otherwise, you can use an on-line site like paste-bin or coliru-stacked to post your code.

If you have compile errors, then post them here verbatim, making sure the line numbers match with your posting of the code. If there are lots of errors, then post the first 5 errors - often later errors are caused by the earlier ones :+)

I hope this helps, and I look forward to helping out.

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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
void playBlackJack(double & wallet)
{
	shuffleCards();
	cout << " Welcome to BlackJack.";
	placeBet (wallet);
	int drawCard();
	int dealer_card1 = getRandomNumber (1,13);  
	int dealer_card2 = getRandomNumber (1,13);	 
	int player_card1 = getRandomNumber (1,13);	
	int player_card2 = getRandomNumber (1,13);


	cout << "\n" << "The dealer has "; 
	switch (dealer_card1) {
		case 1: cout << "Ace and "; 
			break;
		case 11: cout << "Jack and "; 
			break;
		case 12: cout << "Queen and ";
			break;
		case 13: cout << "King and "; 
			break;
		default: cout << dealer_card1 << " and ";
			break;
	}
	switch (dealer_card2) {
		case 1: cout << "Ace"; 
			break;
		case 11: cout << "Jack"; 
			break;
		case 12: cout << "Queen"; 
			break;
		case 13: cout << "King"; 
			break;
		default: cout << dealer_card2;
			break;
	}
	cout << "\n" << "\n" << "You have ";
	switch (player_card1){
		case 1: cout << "Ace and "; 
		break;
		case 11: cout << "Jack and "; 
			break;
		case 12: cout << "Queen and "; 
			break;
		case 13: cout << "King and "; 
			break;
		default: cout << player_card1 << " and "; 
			break;
	}
	switch (player_card2){
		case 1: cout << "Ace"; 
			break;
		case 11: cout << "Jack"; 
			break;
		case 12: cout << "Queen"; 
			break;
		case 13: cout << "King"; 
			break;
		default: cout << player_card2;
			break;
	}

	cout << "\n";
	int dealer_total = dealer_card1 + dealer_card2;
	int player_total = player_card1 + player_card2;
	int choice;
	int cardvalue = drawCard();
	 while ((player_total <= 21) && (choice != 'S' || 's') )
	 {
		cout << " Would you like to (H)it or (S)tand :";

		if(player_total == 21){

          cout<<"Blackjack! You Win"<< endl;
		   4*placeBet (wallet);
       }

       else if (dealer_total == 21){

          cout << (dealer_total, player_total);

		  cout<<" \n Dealer has blackjack, you lose"<<endl;}


		while(player_total <= 21){

          cout<<"Your total is "<<player_total<<endl;

          if(choice =='H' || 'h'){

             player_total += drawCard();

             cout<<"Dealt a "<< drawCard () <<endl;
             }
         
          else{
			  
               cout << " You Stay "<< (dealer_total, player_total);

               //if player stays, let the dealer play

               goto dealer;

          }

        }

       dealer:

       while(dealer_total <= 21){         

          if (dealer_total < 17){

             dealer_total += drawCard();

             cout<<"Dealt a  "<< drawCard() <<endl;                                  
		  }
	   }
	    if(player_total>dealer_total){

                  cout<<"You win!"<<endl;
				  2*placeBet (wallet);
               }

               else if(player_total<dealer_total){

                    cout<<"You lose."<<endl;

               }

               else{

                    cout<<"It's a tie."<<endl;

	 }
	}

}



void displayMenu()
{
  const int nameWidth = 20;
  const int priceWidth = 8;

  std::cout << "Welcome to Bob's Casino" << "\n";
  std::cout << "What game do you want to play?" << "\n";
  std::cout << std::setw(nameWidth) << std::left << "Name";
  std::cout << std::setw(priceWidth) << std::left << "Price";
  std::cout << "Odds" << "\n";

  // Print flip the coin details
  std::cout << std::setw(nameWidth) << std::left << "(F)lip-the-Coin";
  std::cout << std::setw(priceWidth) << std::left << "$0.50";
  std::cout << "2/1" << "\n";

  // Print guess the number details
  std::cout << std::setw(nameWidth) << std::left << "(G)uess-the-Number";
  std::cout << std::setw(priceWidth) << std::left << "$1.00";
  std::cout << "2/1" << "\n";

  // Print street craps details
  std::cout << std::setw(nameWidth) << std::left << "(S)treet Craps";
  std::cout << std::setw(priceWidth) << std::left << "Wager";
  std::cout << "2/1" << "\n";

  // Print blackjack details
  std::cout << std::setw(nameWidth) << std::left << "(B)lackjack";
  std::cout << std::setw(priceWidth) << std::left << "Wager";
  std::cout << "2/1 (4/1 for Blackjack!)" << "\n";

  // Print exit details
  std::cout << "E(x)it" << "\n";
}

// shuffleCards() provided for you. DO NOT CHANGE
void shuffleCards()
{
  // Clear the original deck
  _cards.clear();

  // A container to hold all the suits by priority
  // Clubs, Diamonds, Hearts, Spades
  std::vector<std::string> suits { "C", "D", "H", "S" };
  // A container for unshuffled cards
  std::vector<std::string> unshuffled;
  // Create all of the cards, unshuffled...
  for (int s = 0; s < suits.size(); ++s)
  {
    // Put in the Ace
    unshuffled.push_back("A" + suits[s]); // AC, AD, AH, AS
    // Put in 2 - 10
    for (int val = 2; val <= 10; ++val)
    {
      unshuffled.push_back (std :: to_string(val) + suits[s]);
    }
    // Now add Jack, Queen, and King
    unshuffled.push_back("J" + suits[s]);
    unshuffled.push_back("Q" + suits[s]);
    unshuffled.push_back("K" + suits[s]);
  }

  while (unshuffled.size() > 0)
  {
    // get a random card within range
    int rc = rand() % unshuffled.size();
    std::string card = unshuffled[rc];
    // remove the card from the unshuffled deck
    unshuffled.erase(unshuffled.begin() + rc);
    // Add it to the shuffled card deck
    _cards.push_back(card);
  }

  // Now the _cards variable holds a shuffled deck of cards
}

// printCards() provided for you. DO NOT CHANGE
void printCards()
{
  // A for-loop that will loop as many times as we have cards
  for (int i = 0; i < _cards.size(); i++)
  {
    // Print a number - leave room for 2 so they line up
    std::cout << "[" << std::setw(2) << (i + 1) << "] ";
    // Print the original card representation (e.g. 10C)
    std::cout << std::setw(3) << _cards[i];
    // Print the card value (e.g. 10)
    std::cout << ": " << getCardValue(_cards[i]);
    // Print the card suit (e.g. Clubs) - go to newline
    std::cout << "-" << getSuit(_cards[i]) << "\n";
  }
}
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
86
87
88
89
// getCardValue() provided for you. DO NOT CHANGE
int getCardValue(std::string card)
{
  int val = 0;
  // double check to see if it is a face card
  // cards are a collection of characters (strings)
  // If it is a face card (J,Q,K) or an Ace, then the
  //	first letter (character 0) describes its value
  char face;
  if(card.length() > 0)
  {
    face = card[0];
    switch (face)
    {
    case 'A':
      val = 1;
      break;
    case 'J':
    case 'Q':
    case 'K':
      val = 10;
      break;
    default:
      // If it isn't a face card it's a number card. Default
      //	case statements catch anything not previously caught.
      // string-to-integer (stoi). Cut off the suit indicator
      // Use a substring (substr) to cut off the suit indicator
      // if the card is 10C (10 of clubs), the size is 3.if we 
      // use a substring from location 0 to size()-1 = 2 we get
      // just the 10. Then we use stoi to turn that into an int
      std::string numberOnly = card.substr(0, card.size() - 1);
      val = std::stoi(numberOnly);
      break;
	}
  }
  return val;
}

// getSuit() provided for you. DO NOT CHANGE
std::string getSuit(std::string card)
{
  // Cards are represented by a collection of characters (strings)
  // Example: 10C (10 of clubs)
  // We need to figure out what the suit is by checking only
  //	the last character in the string
  // To determine the last character's index, we use length - 1.
  std::string suit = "";
  if(card.length() > 1)
  {
    char s = card[card.length() - 1];
    // A variable to hold the suit we will return
    switch (s)
    {
    case 'C':// a case statement with no break will 'fall through' to the next
    case 'c':
      suit = "Clubs";
      break; // Execution for C or c stops here
    case 'D':
    case 'd':
      suit = "Diamonds";
      break;
    case 'H':
    case 'h':
      suit = "Hearts";
      break;
    case 'S':
    case 's':
      suit = "Spades";
      break;
    }
  }
  return suit;
}

// drawCard() provided for you. DO NOT CHANGE
std::string drawCard()
{
  std::string card = "";
  if(_cards.size() > 0)
  {
    // Grab the card at the top
    card = _cards[_cards.size() - 1];
    // remove the card off the deck
    _cards.pop_back();
  }

  // return the card to the requestor
  return card;
}
Hi,

Just need to change the code tags a bit, make the code start on what is now line 16 #include <iostream> . The code tags highlight key words in blue amongst other things.

You can also set the firstline number of your code, do this for your second code fragment. Remove the spaces between first line.

[co de first line=340]

You can put individual pieces into code tags, you don't have to do the whole thing:

std::vector<std::string> suits { "C", "D", "H", "S" };
here { has a red squiggle that says " expected a ;"

and

unshuffled.push_back (std :: to_string(val) + suits[s]);

where std says " more than one instance of overloaded function " std :: to_string" matches the arguments list.


Although shuffleCards() is a function my professor gave me so I would think that was the problem.

This is what I have.

1
2
3
4
5
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
using namespace std;



340
341
342
343
void playBlackJack(double & wallet)
{
	shuffleCards();
	cout << " Welcome to BlackJack.";


Last edited on
Ok,

In addition to my last, a post of your actual compiler errors would be good, it saves having to scroll through all your code to find where the problem is.

Cheers :+)
std::vector<std::string> suits { "C", "D", "H", "S" };

Which compiler are you using? I have a vague idea that VS might require an = for braces initialisation.

Not sure about the other error.

Some other things I noticed:

You have using namepace std; in some parts of your code, do things correctly with std:: in other parts. Remove the using namepace std; to make the whole thing better.

There are a few instances of this sort of thing:
if(choice =='H' || 'h'){

It should be :

if(choice == 'H' || choice == 'h'){

On that, halve your logic by making use of the toupper function, then you only have to do this:

if(choice == 'H' ){

Rather than checking both each time.

Avoid goto , you could have just used break

Hopefully that is a start :+)





Topic archived. No new replies allowed.