Problem with if command

hello.

I am beginner in C++. I wrote this code but when i execute it and enter the letter F I get the same result as if i entered D. Look at the code and help me plz tnx :)

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
#include <iostream>
#include <windows.h>
#include <string>
#include <dos.h>

// Read user input and use it in system() command//
int system(const char *command);



int main()

{
    using namespace std;
    char x;
    char y;
    int d;
    int f;
    char v;

    system("color 1e");

    cout << "\t\t!!!!WELCOME TO MR.ZAP'S PDF SCANNER!!!! \n\n\nHERE YOU CAN SCAN YOU HARD DISK FOR AVAILABLE .PDF FILES";


    cout << "\n\nDO YOU WANT ME TO SCAN A DISK OR A SPECIFIC FOLDER. \n\nTYPE D for disk OR F for folder.:\n\n";

    cin >> y;

    if (y = d)
    {
    cout << "\n\nSPECIFY THE DISK YOU WANT TO SCAN AND HIT ENTER.: " << endl;

    cin >> v;

	string cmdLine = "forfiles.exe /p ";
	cmdLine += v;
	cmdLine += ":\\ /s /m *.pdf";
	system(cmdLine.c_str());
    }
    else if (y = f)
    {
    cout << "\n\nSPECIFY THE FOLDER YOU WANT TO SCAN AND HIT ENTER.: " << endl;

    cin >> x;

	string cmdLine = "forfiles.exe /p ";
	cmdLine += x;
	cmdLine += ":\\ /s /m *.pdf";
	system(cmdLine.c_str());
    }

return 0;

}

couldn't really test it because i got a C drive, anyway

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 <windows.h>
#include <string>
#include <dos.h>

// Read user input and use it in system() command//
int system(const char *command);



int main()

{
    using namespace std;
    char x;
    char y;
    char v;

    system("color 1e");

    cout << "\t\t!!!!WELCOME TO MR.ZAP'S PDF SCANNER!!!! \n\n\nHERE YOU CAN SCAN YOU HARD DISK FOR AVAILABLE .PDF FILES";


    cout << "\n\nDO YOU WANT ME TO SCAN A DISK OR A SPECIFIC FOLDER. \n\nTYPE D for disk OR F for folder.:\n\n";

    cin >> y;

    if (y = 'd')
    {
    cout << "\n\nSPECIFY THE DISK YOU WANT TO SCAN AND HIT ENTER.: " << endl;

    cin >> v;

	string cmdLine = "forfiles.exe /p ";
	cmdLine += v;
	cmdLine += ":\\ /s /m *.pdf";
	system(cmdLine.c_str());
    }
    else if (y = 'f')
    {
    cout << "\n\nSPECIFY THE FOLDER YOU WANT TO SCAN AND HIT ENTER.: " << endl;

    cin >> x;

	string cmdLine = "forfiles.exe /p ";
	cmdLine += x;
	cmdLine += ":\\ /s /m *.pdf";
	system(cmdLine.c_str());
    }

return 0;

}


should work
Also:
if (y = 'd')
should be
if (y == 'd')

In C++ = assigns a value and == tests a value.
Topic archived. No new replies allowed.