My C++ project.. :-/

For my C++ project I have to create a few casino games. I have just started, and a few things aren't working.. I only have the High-Low game working right now, but whenever I enter "Lower" as input, it reads it as "Higher" for some reason. It works fine if "Higher" is my input. And it also doesn't loop properly, and I have no idea why that is..

So any kind of help would be awesome.. thank you :)

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

//maria.boyle
#include<iostream>
#include<ctime>

using namespace std;

int main ()

{

	int choice;

//random
	srand((unsigned)time(0));
	int randa = 100;
	int randb = 100;
		int money = rand()%randb+randa;


//welcome
	cout<<"Welcome to the Eiselen Casino!\n\nYou have $"<<money<<" to gamble with.\n\nYou can play High-Low, Roulette, Blackjack, or Slots. You may play for how ever long you would like as long as you do not bust. \nGood luck!\n\n";

//do while

	do {

		cout<<"You currently have $"<<money<<" to gamble with.\nWhat casino game would you like to play?\n"
			<<"1) High-Low\n"
			<<"2) Roulette\n"
			<<"3) Blackjack\n"
			<<"4) Slots\n"
			<<"5) I want to leave\n";
		cin>>choice;

		{
		if (choice == 1) {
			srand((unsigned)time(0));
			int num = rand()%10;
			int num2 = rand()%10;
			int highlowbet;
			char HLguess;
			int payoff = 1;
			cout<<"\nHIGH-LOW. The computer will generate a random number between 0 and 10. Choose whether or not the next number will be higher or lower than the first one.\n"
				<<"I would like to bet $";
			cin>>highlowbet;
	//invalid entry
				if (highlowbet < 1 || highlowbet > money){
					cout<<"You can't bet that. Try again. What is your bet? $";
						cin>>highlowbet; }

			cout<<"The first number is "<<num<<". Think the number is higher or lower than "<<num<<"? (Respond with either 'Higher' or 'Lower')\n";
			cin>>HLguess;

				if (HLguess = "Higher" && num < num2){
					cout<<"You're right! It was higher.";
					cout<<"The number was "<<num2<<".\n";
					money = money + payoff*highlowbet;
				}
				else if (HLguess = "Higher" && num > num2){
					cout<<"You're wrong. It was lower.";
					cout<<"The number was "<<num2<<".\n";
					money = money - highlowbet;
				}
				else if (HLguess = "Lower" && num < num2){
					cout<<"You're wrong. It was higher.";
					cout<<"The number was "<<num2<<".\n";
					money = money - highlowbet;
				}
				else if (HLguess = "Lower" && num > num2){
					cout<<"You're right! It was lower.";
					cout<<"The number was "<<num2<<".\n";
					money = money + payoff*highlowbet;
				}
				system("PAUSE");
		}

		else if (choice == 2) {
			cout<<"roulette\n";
		}

		else if (choice == 3) {
			cout<<"blackjack\n";
		}

		else if (choice == 4) {
			cout<<"slots\n";
		}

		else if (choice == 5) {
			return 0;
		}

		else if (choice != 5) {
			cout<<"Invalid entry. Try again\n\n";
		}
		}
	
	} while (choice !=5);
}
firstly, HLguess is a char, so it can only be 'h' or 'l'. use string instead. secondly, in lines 55 60 65 70 '=' is assignment not comparision. make that ==.

also, some lesser problems: on line 48 there should be while instead of if, so that "try again" message is displayed as many times as needed. on line 94 you dont need if, becouse this line will only be executed if choice!=1,2,3,4 and 5. and on line 99 this may as well be while(true), becouse if choice == 5 there is another way out.
Last edited on
Ahhh perfect. Thank you very much. :)
Topic archived. No new replies allowed.