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;		
	infile.open("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);
		ctr1++;
	}


	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]!=' ') 
		wordstar[n]='*';
	}
	



	cout<<"Spin and Win!!!!"<<endl;
	cout<<"You start with $10000"<<endl;
	cout<<endl;
	cout<<"The phrase is "<< wordstar <<endl;	//outputs user's word
	cout<<endl;
	
	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<<endl;
		cout<<"What's your guess? "<<endl;
		cin>>guess;
		

		
		if(word.find(guess)!=string::npos)
		{	
		for (int x=0; x<=word.length()-1; x++)
			{
			if(word[x]!=' ')
				{
					wordstar[x]='*';
				}
			}
		}	
			
			numOfGuess=howManyChar(word, guess);

			money=money+(numOfGuess*spinamt);

			cout<<"There are "<<numOfGuess<<" "<<guess<<"'s"<<endl;
			cout<<"You now have "<<money<<endl;
			cout<<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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.