(Win32 Console project) Can't think of a good title here

The source is bellow. There is an error I fail to understand and to fix. This is just a small unscramble the word program I began.


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
#include <iostream>
#include <string>
using namespace std;
int out_of_tries()
{
cout << "You have 0 attempts left, hard luck\n";
system ("pause");
	return 0;
}
int two_tries_left()
{
cout << "You have 2 attempts left\n";
}
int one_try_left()
{
cout << "You have 1 attempts left\n";
}
int main()
{
	int a = 3;
	string a1, a2, a3;
	loop:
	cout << "unsrcamble this word: luzpze\n";
	cin >> a1;
	if (a1 == "puzzle")
	{
    a = a;
	}
	else 
	{
    a = a - 1;
	if (a == 2)
	{
	two_tries_left();
	goto loop;
	}
	else if (a == 1)
	{
		one_try_left();
		goto loop;
	}
	else if (a == 0)
	{
    out_of_tries();
	}
	else
	{
     cout << "You shouldn't view this";
	}
	}
system ("pause");
return 0;
}
Try changing the 'int's of lines 4, 10 and 14 to 'void' and adding '#include "StdAfx.h"' to the beginning of your file.
Actually, leave the 'int' on line 4.
Now the 'return 0;' lines have an error saying "the line does not match any functions types", and my editor cannot open "StdAfx.h" .
Post the exact error that your compiler said.
1>------ Build started: Project: project12, Configuration: Debug Win32 ------
1> code12.cpp
1>c:\users\owner\documents\visual studio 2010\projects\project12\project12\code12.cpp(1): fatal error C1083: Cannot open include file: 'StdAfx.h': No such file or directory
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Oh, when I missed you second post.

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
#include "StdAfx.h"
#include <iostream>
#include <string>
using namespace std;
int out_of_tries()
{
cout << "You have 0 attempts left, hard luck\n";
system ("pause");
	return 0;
}
void two_tries_left()
{
cout << "You have 2 attempts left\n";
}
void one_try_left()
{
cout << "You have 1 attempts left\n";
}
int main()
{
	int a = 3;
	string a1, a2, a3;
	loop:
	cout << "unsrcamble this word: luzpze\n";
	cin >> a1;
	if (a1 == "puzzle")
	{
    a = a;
	}
	else 
	{
    a = a - 1;
	if (a == 2)
	{
	two_tries_left();
	goto loop;
	}
	else if (a == 1)
	{
		one_try_left();
		goto loop;
	}
	else if (a == 0)
	{
    out_of_tries();
	}
	else
	{
     cout << "You shouldn't view this";
	}
	}
system ("pause");
return 0;
}


The only problem is it cannot open "stdafx.h"
So I didn't add the file in. It works perfect now, thanks.
Glad I could help.
Topic archived. No new replies allowed.