error c2678 and c2065

Pages: 123
@kemort
std::toupper() without the header <locale>??
closed account (48T7M4Gy)
Same same closed_letters&numbers
Ok I have tinkered with the code and this is what I have right now.

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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
int main()
{
	char direction;
	string directionerror = "Invalid direction. Please choose again.";


	cout << "Welcome to the movement tutorial." << endl
		<< "You are in Area 1." << endl
		<< "Go North to Area 2." << endl;
	cin >> direction;
	
	for(;;)
	{
		if (direction == 'n' || direction == 'N')
		{
			cout << "Good you made it to Area 2." << endl;
			break;
		}
		else if (direction == 's' || direction == 'S' || direction == 'e' || direction == 'E' || direction == 'w' || direction == 'W')
		{
			cout << "No you imbecile the only way out of Area 1 is to go North."
				<< endl;
			cin >> direction;
		}
		else
		{
			cout << directionerror << endl;
			cin >> direction;
		}
	}

	cout << "Now, to further your experience with moving, go east to Area 3." << endl;
	cin >> direction;
	for (;;)
	{
		if (direction == 'e' || direction == 'E')
		{
			cout << "Congratulations! You have made it one step further to completeing your goal." << endl;
			break;
		}

		else if (direction == 's' || direction == 'S')
		{
			cout << "Opps wrong way. You are now in Area 1 again."<<endl;
			cout << "Go back to Area 2 by heading North." << endl;
			cin >> direction;
			for (;;)
			{
				if (direction == 'n' || direction == 'N')
				{
					cout << "Good job now go to Area 3 (which is East)." << endl;
					cin >> direction;
					break;
				}

				else if (direction == 'e' || direction == 'E' || direction == 's' || direction == 'S' || direction == 'w' || direction == 'W')
				{
					cout << "*Donk* Hey there is a wall there." << endl;
					cin >> direction;
				}
				else
				{
					cout << directionerror << endl;
					cin >> direction;
				}
			}
		}

		else if (direction == 'n' || direction == 'N' || direction == 'e' || direction == 'E')
		{
			cout << "Am I talking to just hear myself?" << endl
				<< "Listen to what I am telling you and go East." << endl;
			cin >> direction;
		}
		else
		{
			cout << directionerror << endl;
			cin >> direction;
		}
	}

	cout << "Alrigt just one more room to go." << endl 
		<< "Now you must go South to enter Area 4 and finish the movement tutorial." << endl;
	cin >> direction;
	for (;;)
	{
		if (direction == 's' || direction == 'S')
		{
			cout << "Do do do doo doo doo do doo dooo! You have completed the movement tutorial!" 
				<< "Please open the next application to continue with the tutorials.";
			break;
		}

		else if (direction == 'w' || direction == 'W')
		{
			cout << "Now you are back tracking. You have just reentered Area2." << endl
				<< "You need to head back to Area 3 (Which is East)." << endl;
			cin >> direction;
			if (direction == 'e' || direction == 'E')
			{
				cout << "Welcome back to Area 3. Now finish the tutorial by going south." << endl;
				cin >> direction;
			}

			else if (direction == 's' || direction == 'S')
			{
				cout << "I give up. You are incompetent of following orders." << endl;
				cin >> direction;
				for (;;)
				{
					if (direction == 'n' || direction == 'N')
					{
						cout << "Good you are finally starting to listen." << endl;
						cin >> direction;

						if (direction == 'e' || direction == 'E')
						{
							cout << "Finally you are in Area 3 again. Go south to leave me alone." << endl;
							cin >> direction;
							break;
						}
						else if (direction == 'n' || direction == 'N' || direction == 'w' || direction == 'W' || direction == 'e' || direction == 'E')
						{
							cout << "Enough!!! Come back when you learn to follow orders!!!" << endl;
							system("PAUSE");
							return 0;
						}
						else
						{
							cout << directionerror << endl;
							cin >> direction;
						}
						
					}
					else if (direction == 's' || direction == 'S' || direction == 'w' || direction == 'W' || direction == 'e' || direction == 'E')
					{
						cout << "Dumbass." << endl;
						cin >> direction;
					}
					else
					{
						cout << directionerror << endl;
						cin >> direction;
					}
				}
			}

			else if (direction == 'n' || direction == 'N' || direction == 'w' || direction == 'W')
			{
				cout << "Hey there is a wall there." << endl;
				cin >> direction;
			}
			else
			{
				cout << directionerror << endl;
				cin >> direction;
			}

		}

		else if (direction == 'n' || direction == 'N' || direction == 'e' || direction == 'E')
		{
			cout << "For crying out loud I told you to listen to what I tell you. Why do you insist on walking into walls!" << endl;
			cin >> direction;
		}
		else
		{
			cout << directionerror << endl;
			cin >> direction;
		}
	}

	

	system("PAUSE");
    return 0;
}


I know it is very sloppy right now but it works (for the most part). My next question is what can i do to shorten the code so it looks neater? Any help would be greatly appreciated.
> My next question is what can i do to shorten the code so it looks neater?

Use toupper() from <ctype>. By using it, you can shorten your if-code by half.

For example :
if (direction == 'n' || direction == 'N' || direction == 'w' || direction == 'W')

==>
if (toupper(direction) == 'N' || toupper(direction) == 'W')
Does that help? :)
@closed account 5a8Ym39o6

Yes it helped with shortening the If statements but what I was really asking for was is there an easy way to shorten the If parameters? Or do you think it is fine as is?

Edited:
Or really to not use as many if statements all together but still keep the same effect. I can't see any way to do it but hey I am new lol.
Last edited on
closed account (48T7M4Gy)
You can simplify this quite a lot if you use game-state-management techniques. It's worth reading up on it but it can be done fairly simply here by tables which would show where you are currently in the game and then lookup where you can go from that position with appropriate messages and responses.
@kemort

Thank you for the response do you happen to have a reference that you can link to me? If not that is fine I just want to have a good source to look into.
closed account (48T7M4Gy)
http://lazyfoo.net/articles/article06/index.php

You could start with this site to get the idea of how to organise your game in a different but more manageable way. Your game will be fairly easily adapted once you get into it.
Thank you again. I will read into it and show you what I come up with
Topic archived. No new replies allowed.
Pages: 123