Project help

Hi im quite a programming noob :) could anyone tell me why this for loop is asking for another semi-colon? Just say if yous need more code :)

string ChooseCategorySelectRandomWord(){
int userChoice = 0;
cout << "Please choose a catagory" << endl << "1.Sports" << endl << "2.Food" << endl << "3.Countries" << endl << "4.Movies" << endl << "5.Games" << endl; // This asks and displays options for the user
cin >> userChoice;

if( between(userChoice, 1, 5) ){
string filename = wordFiles[userChoice-1];

ifstream in (filename);
string wordToGuess;


srand ( time(NULL) );
int r = rand() %20;

do
in>> stringToGuess;
while ( --r >= 0 );

cout << stringToGuess << endl;

return stringToGuess;
} else {
for (!between(userChoice, 1, 5)) {
cout << " Enter A Number Between 1 And 5" << endl;
userChoice = 0;
cin >> userChoice;
for (!between(userChoice, 1, 5)) the second bracket has an error message saying expected a ;
The do-while loop?

Alright the syntax for do-while loops looks like this

1
2
3
4
5
6
do
{

// Do Some Stuff

}while(expression);


You may want to look over the do while loop you have. Your missing brackets. If you put that in, I think it should fix your error.
Last edited on
cheers i added that but it is still saying expecting ; and nah the for.
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
#include <iostream> 
#include <string>
#include <fstream>
#include <time.h>
#include <cstdlib>
#include <stdlib.h>

using namespace std;

string wordFiles[] = {"Sports.txt", "Food.txt", "Countries.txt", "Movies.txt", "Games.txt"};
string replacement="";

string wordsToGuess[20];
string stringToGuess;    //word trying to guess
string wordGuesses;     //all the letters you guess
char guess;           //The letter the user is guessing
string filename;     //Name of file to be opened
int r;
string username;
int pos;


bool between(int number, int min, int max){
	return (number >= min && number <= max);
}



string ChooseCategorySelectRandomWord(){
	int userChoice = 0;
	cout << "Please choose a catagory" << endl << "1.Sports" << endl << "2.Food" << endl << "3.Countries" << endl << "4.Movies" << endl << "5.Games" << endl; // This asks and displays options for the user
	cin >> userChoice;

	if( between(userChoice, 1, 5) ){
		string filename = wordFiles[userChoice-1];

		ifstream in (filename);
		string wordToGuess;


		srand ( time(NULL) );
		int r = rand() %20;

		do{
		in>> stringToGuess;
		}while ( --r >= 0 );

		cout << stringToGuess << endl;

		return stringToGuess;
	} else { 
		for (!between(userChoice, 1, 5)) {
			cout << " Enter A Number Between 1 And 5" << endl; 
			userChoice = 0;
			cin >> userChoice;
}
	}
}
string initialize_guess(){
	int n = stringToGuess.size();
	string initial_word_string;
	for(int i = 0; i <n; i++)
		initial_word_string += '*';
	cout << initial_word_string << endl;
	return initial_word_string;
}

string replace_character (int pos){

	string initial_word_string ="";

	for (int i = 0; i<initial_word_string.size(); i++) 

		if(i == pos){
			replacement += guess;
		}else
		{
			replacement += initial_word_string.at(i);
		} 
		return replacement;
}

bool test_guess(){ 
	///std::string str(1, guess);
	pos = stringToGuess.find(guess);
	if(pos < 0){ 
		return false;
	}
	wordGuesses = replace_character(pos);
	cout << wordGuesses << endl ;
	return true;
}



string get_guess()

{

	cout << "Please enter a letter" << endl;
	cin >> guess;

	do {
		test_guess();
		cout << "Please enter another letter" << endl;
		cin >> guess;
	}
	while (test_guess() == true);
	do {
		if (test_guess() == false);
		cout << "Wrong! Enter another letter" << endl ;
		cin >> guess;
	} while (test_guess() == false);
	return 0;
}

void main ()
{
	char name[50];
	cout << "Please enter your name" << endl;
	cin.getline (name, 50);
	cout << name << endl;
	bool done = false;
	ChooseCategorySelectRandomWord();
	initialize_guess();
	while(!done){
		string g = get_guess();
		if(g.size() > 1){
			if (test_guess() ){
				done = true;
				cout << "Win";
			} else {
				//score += //
				replace_character(g.at(0));
				//if(guessWord == wordToGuess){
				//	cout << score;
			}
		}
	}


	get_guess();

}


Thats all my code xD its for a game of hangman.
Topic archived. No new replies allowed.