Issues in function

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
#include <iostream>
#include <cwchar>
#include <string>
#include <Windows.h>
using namespace std;
#include <stdlib.h>;

char response;
string fname;


int main()
{
    

    cout << "Would you like to play a game? Y/N?";

    cin >> response;
    if (response == 'y');
        cout << "What game would you like to play? Please type in exactly what the game is called including spaces, dashes, or capitalization.";
    cin >> fname;

    WIN32_FIND_DATA file;
    HANDLE search_handle=FindFirstFile("C:\\*",&file);
    if (search_handle)
    {
        do
        {
            if(0 == strcmp) //I dont know where to put the fname or splitpath bit 
		{CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) ||
		ShellExecute(handle, "find", <fully_qualified_path_to_folder>, NULL, NULL, 0)||  //handle is undefined
		//and the <fully.... expected an expression
ShellExecute(handle, NULL, <fully_qualified_path_to_folder>, NULL, NULL, SW_SHOWNORMAL);


    std::cout << "Found the game you wanted to play!" << std::endl;
}
        while(FindNextFile(search_handle,&file));
        FindClose(search_handle);



    system("pause");



	
    if (response == 'n')
        cout << "Goodbye!";

    //countdown
 Sleep (1 * 1000);
	 cout << "5"<<endl;
	  Sleep (1 * 1000);
	  cout << "4"<<endl;
	   Sleep (1 * 1000);
	   cout << "3"<<endl;
	    Sleep (1 * 1000);
		cout << "2"<<endl;
		 Sleep (1 * 1000);
		 cout << "1"<<endl;
		 Sleep (1 * 1000);
  cout << "CIAO!\n"<<endl;
  Sleep (1 * 1000);
  return 0;
		}  //for some reason it says that it expected 'while' 
Your braces are mismatched. On line 30, you open braces for a code block after the if statement. However, the next close-brace it finds is on line 37. This is where it closes the if block, but the do block is still open. The compiler therefore interprets line 38 as a while statement that does nothing.

The next close brace is the one at line 66, so it interprets that as the end of the do loop.

You would find it much easier to see this for yourself if you bothered to adopt a sensible, consistent indentation style.

Talking of statements that do nothing, line 19 doesn't do what you probably want it to, which means that line 20 will execute when you don't expect it to.

And even if you fixed line 19 so that 19 and 20 work as you want them to, what do you think would happen if the user entered 'N'?
Last edited on
I went through it, changed some stuff, and still the braces are messed up. When I type 'n' it doesn't begin the countdown. Here it is:

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
#include <iostream>
#include <cwchar>
#include <string>
#include <Windows.h>
using namespace std;
#include <stdlib.h>;

char response;
string fname;


int main()
{
    cout << "Would you like to play a game? Y/N?";
    cin >> response;
	if (response == 'n')
	{
        cout << "Goodbye!";
	
    //countdown
      Sleep (1 * 1000);
	 cout << "5"<<endl;
	  Sleep (1 * 1000);
	  cout << "4"<<endl;
	   Sleep (1 * 1000);
	   cout << "3"<<endl;
	    Sleep (1 * 1000);
		cout << "2"<<endl;
		 Sleep (1 * 1000);
		 cout << "1"<<endl;
		 Sleep (1 * 1000);
  cout << "CIAO!\n"<<endl;
  Sleep (1 * 1000);
  return 0;
}
    if (response == 'y' || response == 'Y');
	{
        cout << "What game would you like to play? Please type in exactly what the game is called including spaces, dashes, or capitalization.";
    cin >> fname;

   WIN32_FIND_DATA file;
    HANDLE search_handle=FindFirstFile("C:\\*",&file);  //Not sure if I should change the file  part, but it's undefined.
    if (search_handle)
    {
        do
        {
           if(0 == strcmp(fname, "a"))  //No suitable  conversion function from string to char exists 
		{CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) ||
		ShellExecute(handle, "find", <fully_qualified_path_to_folder>, NULL, NULL, 0)||  //handle is undefined
		//and the <fully.... expected an expression
ShellExecute(handle, NULL, <fully_qualified_path_to_folder>, NULL, NULL, SW_SHOWNORMAL);

    std::cout << "Found the game you wanted to play!" << std::endl;

        while(FindNextFile(search_handle,&file))
        FindClose(search_handle);
    system("pause");
		}
		   return 0;
		}
Your while condition should be immediately after the do block, not in the middle of it.

Does your code even compile? I can't see the brace that closes the block that opens at line 44.

You've completely ignored my advice to use a sensible indentation style. Seriously, this isn't something that prissy developers say because they're anal-retentive about tidiness. It's because it will help you see what your code is doing and where you're making mistakes.

Start doing it. Keep doing it. Do it until it becomes second nature. It will help YOU.
Topic archived. No new replies allowed.