Compiling issues due to if and else if statements

Have a hw issue. my code is not compiling and visual studio is giving me errors all around the if and else if statements saying "expected declaration" or "expected statement" and Illegal else with out matching if.

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
 #include<iostream>
#include<time.h>
using namespace std;

int main(void)
{
	while (true)
	{
	srand(unsigned(time(0)));
	
	int number = rand() % 1000 + 1;
	int guess;
	char choice;
	char choice2;
	char choice3;
	char choice4;
	char hotOrCold;
	int theGuessedNumber = 500;

	cout << "I want to play a game" << endl;
	cout << "If you want to guess my # enter ""y""" << endl;
	cout << "If you want me to guess your # enter ""n""";
	cin >> choice;
		if (choice != 'y' || choice != 'n')
			{
			cout << "unnaccepted response, please enter ""y"" or ""n""" << endl;
			}

		else if (choice == 'y')
		{
			//YOU GUESS GAME
			//Begin Loop
			while (true)
			{
				cout << "I am thinking of a # between 1 and 1000, guess a #";
				cin >> guess;
				if (number<guess)
				{
					cout << "Too high try again" << endl;
				}
				else if (number>guess)
				{
					cout << "Too low try again" << endl;
				}
				else if (number == guess)
				{
					cout << "Congratulations, you guessed it!";
					cout << endl;
					cout << "If you want to play again type ""y"" if not ""n""" << endl;
				}
				cin >> choice2;
				if (choice2 != 'y' || choice2 != 'n');
				{
					cout << "unnaccepted response, please enter ""y"" or ""n""" << endl;
				}
				else if (choice2 == 'y')
				{
					break;
				}
				else if (choice2 == 'n')
				{
					return 0;
				}
			}
		}
		else if (choice == 'n')
		{
			// I GUESS GAME
			// Begin Loop
			while (true)
			{
				cout << "Think of a number between 1 & 1000" << endl;
				cout << endl;
				cout << "Are you ready? Type ""y"" for yes and ""n"" for no";
			}
			cin >> choice3;
				if (choice3 != 'y' || choice3 != 'n');
				{
					cout << "unnaccepted response, please enter ""y"" or ""n""" << endl;
				}
				else if (choice3 == 'y')
				{
					cout << "After I guess please tell me if I am high, low, or correct. Using key below:" << endl;
					cout << "C = correct" << endl;
					cout << "H = too high" << endl;
					cout << "L = too low" << endl;
					cout << endl;
					cout << "My first guess is:" << theGuessedNumber << endl;
				}


			while (true)
			{
				if (hotOrCold == 'H')
				{
					theGuessedNumber = theGuessedNumber / 2;
				}
				else if (hotOrCold == 'L')
				{
					theGuessedNumber = theGuessedNumber * 1.5;
				}
				else if (hotOrCold == 'C')
				{
					cout << "I KNEW IT!!!";
					cout << endl;
					cout << "If you want to play again type ""y"" if not ""n""" << endl;
					
					cin >> choice4;
					
					if (choice4 != 'y' || choice4 != 'n');
					{
						cout << "unnaccepted response, please enter ""y"" or ""n""" << endl;
					}
					else if (choice4 == 'y')
					{
						break;
					}
					else if (choice4 == 'n')
					{
						return 0;
					}
				}
				cout << theGuessedNumber << endl;
				cin >> hotOrCold;
				if (hotOrCold != 'C' || hotOrCold != 'H' || hotOrCold != 'L')
				{
					cout << "Please give valid hint using ""C"", ""H"", or""L""." << endl;
				}
			}
		}
			return 0;
	}
}
Make sure you're not putting semicolon at the end of if statement lines.

You should also move the call to srand outside the loop to avoid reseeding the the random number generator each time.
Line 24,52,77,110,125: Your boolean condition is wrong. Those statements are always going to evaluate as true. If choice is 'y', then choice != 'n' will be true and if choice is 'n', then choice != 'y' will be true. You want &&, not ||.

Line 52,77,110: Remove the ; The ; terminates the if statement.
Topic archived. No new replies allowed.