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.
//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"
usingnamespace 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((unsignedint)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;
}
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.
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: