My program is supposed to essentially be something like Wheel of Fortune. As long as the user guesses letters that aren't in the word, the program behaves properly. But, when the user inputs a letter that IS in the word, the program stops and doesn't continue at all.

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

int howManyChar(string word, char guess);

int main()
	int numph;		//First number in .dat file saying how many worsd there are
	int wordnum;	//Number of which word in the list the program uses
	int ctr1=0;		//Counter for first loop
	string word, wordstar;	//Word that the user is trying to guess
	int money=10000;		//Number of money
	int spinamt;	//Amount user spun for
	char guess;		//Letter that user is guessing
	int numOfGuess;	//How many times their guess was in the word

	srand(time(NULL));		//Seeds system time for rand()

	ifstream infile;"words.dat");	//Calls my data file with the words
	infile>>numph;				//Gets the number of words in file

	wordnum=rand()%numph+1;		//Obtains a value that is >=1 and <=5


	while(ctr1!=(wordnum+1))		//Takes number of their word and goes through list
	{								//that many times to obtain their word
		getline(infile, word);

	wordstar=word;			//Sets another string equal to their word

	for (int n=0; n<=word.length()-1; n++)	//If any letters in their word aren't spaces
	{										//they become stars in the output
		if(wordstar[n]!=' ') 

	cout<<"Spin and Win!!!!"<<endl;
	cout<<"You start with $10000"<<endl;
	cout<<"The phrase is "<< wordstar <<endl;	//outputs user's word
	while((money>0)&&(wordstar.find('*')!=string::npos))	//Main game driver
		spinamt = (rand()%20+1)*50;		//Gets a spin amount that is a multiple of 50
									//and no more than 1000, but no less than 50

		cout<<"Tick tick tick ... Tick Tick ... Tick"<<endl;
		cout<<"You spun "<<spinamt<<endl; //Tells user what their amount spun is
		cout<<"What's your guess? "<<endl;

		for (int x=0; x<=word.length()-1; x++)
			if(word[x]!=' ')
			numOfGuess=howManyChar(word, guess);


			cout<<"There are "<<numOfGuess<<" "<<guess<<"'s"<<endl;
			cout<<"You now have "<<money<<endl;
			cout<<"The phrase is "<<wordstar<<endl;
	return 0;

I don't understand what lines 75-81 are supposed to do. wordstar has already been loaded with '*''s. Why do it again?

Where do you define howManyChars()?

Where do you replace the '*' in wordStar with guess if guess is in word?

I believe the body of the if statement staring on line 71 should end on line 91, not on line 82.

This article has been dead for over six months. Start a new discussion instead.