Wheel of fortune game

I am having a little trouble with this wheel of fortune type game, it keeps giving me an error that i cannot find. It would be a great help if someone can help me find the error or help me fine tune everything.

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
//Program to exercise knowledge of loops, decision
//structures, string handling, random number generation,
//and string generation
//CSCI 1010 Pass6
//Chase Garland

#include <iostream>
#include <iomanip>
#include <random>
#include <string>
#include "getWord.h"

using namespace std;


int main()
{
	// Declare variables
	double playerWinnings;
	int spinValue = 0, plays = 10, letterCount; // watch initialization
	string word, disp;
	char spin, guess;
	bool flag;
	int wordLen = 0, lcount = 0; // not a double

	cout << "Welcome to Chase Garland's Diet and Exercise Wheel of Fortune Game" << endl;
	cout << endl;
	/* srand(word == getWord());
	wordLen = word.length();
	if (wordLen <= 10)
	{
		plays = 10;
	}
	else
	{
		plays = wordLen + 4;
	}
	disp = "****************************************";
	disp = disp.substr(0, wordLen); */
	// Initialize Random Seed value using the current time.
	srand((unsigned int)time(0));	// initialize the random seed with call to srand function
	// Call getWord Function to obtain the secret word
	word = getWord();		   // get a random word
	// word="diet";                    // use forced word value for initial testing
	word="diet";
	// Calculate word length
	wordLen = word.length();	   // compute length of the word

	// Establish number of plays - if word len<=10 plays=10 else plays = wordlength.
	(wordLen <= 10) ? plays = 10 : plays = wordLen + 4;

	// initialize Display field
	disp = "*****************************************";	// initialize the display field
	disp = disp.substr(0, wordLen);

	// Setup formatting for dollars
	cout << setprecision(2) << fixed << showpoint; // setup

	// Begin main logic Do-while loop
	do // do-while structure was incorrect and did not have a conditional
	{
		// continue coding
		cout<< "Guess the word: "<< disp << endl;
		cout<< "Your winnings so far are $"<< playerWinnings << "." << " You have " << plays << "spins left." << endl;
		cout<<endl;
		cout<< "Enter (s) to spin the wheel or (q) to quit"<< endl;
		cin>> spin;
		if (spin != 's' || spin != 'q')
		{
			break;
		}
		if (spin == 'q')
		{
			break;
		}
		spinValue=rand()%10*10;
		plays= plays - 1;
		if (spinValue == 30 || spinValue == 60)
		{
			cout<< "Bankrupt"<<endl;
			playerWinnings = 0;
			continue;
		}
		else
		{
			cout<< "The value of the spin is $"<< spinValue << endl;
		}
		cout<< "Guess a letter - (Enter a lowercase letter a-z.)"<<endl;
		cin>> guess;

		bool flag = false;
        for (int i=0; i<disp.length(); i++)
		{
			if (disp.at(i)==guess)
			{
				bool flag = true;
			}
			if (flag== true)
			{
				cout<< "Letter has already been selected"<<endl;
				plays = plays - 1;
				continue;
			}
			else
			{
				letterCount = 0
			}
		}
		
		for (int i=0; i<word.length(); i++)
		{
			if (word.at(i)==guess)
			{
				letterCount++;

				disp.at(i)=guess;
			}
			if (letterCount > 0)
			{
				playerWinnings+=spinValue * letterCount;
			}
			else 
			{
				cout<< "Guess was not found"<<endl;
			}
		}
        // Note: warning C4101 unreferenced local variables will show in "Error List" 
		// until coding is completed

	} while (plays>0 && word != disp);

	// continue coding
	if (disp==word)
	{
		cout<< "Congratulations you guessed the word!!!!! "<< word << endl;
		cout<< "You won a total of $"<< playerWinnings << endl;
	}
	else 
	{
		cout<< "Please play again"<< endl;
	}
    // added command to allow screen capture
	system("pause");
	return 0;
}
Last edited on
@manchester389

Well, since you didn't supply the "getWord.h" file, I removed it. I found you forgot a semi-colon at the end of the line that reads letterCount = 0. Also, changed if (spin != 's' || spin != 'q') to if (spin != 's' && spin != 'q'), because whether you type a 's' or even a 'q', the check fails, since the 's' is NOT a 'q' and the 'q', is NOT an 's'. You need the AND symbol there, '&&'. After that, your game plays. If you had put your code in the code tags, I could have just specified the line number. You could still put in code tags, by highlighting the above code, and then clicking the box on the right that shows <>. That would be a BIG help to all other people that are on this site, trying to help you. You first, should help them.

Games starting to look pretty good.
Last edited on
You aren't actually using anything from <random>. srand and rand are declared in <cstdlib>, so you should include that. And time is declared in <ctime>.

I can't read your code well enough to help with anything else. You need to use code tags:

[code]
your code goes here
[/code]
it keeps giving me an error that i cannot find

What is the error? How can we reproduce it? Describing these things will get you much faster answers.
Topic archived. No new replies allowed.