Error in Source Code

Hi all!
I am making a random password generator (source code below). The user enters the amount of characters the password must be, and depending on that value (Choice), the program calls the appropriate function. I haven't worked out the whole switch statement and the other functions yet, but the meaning is clear, I hope :). The problem is: when I run the program (it compiles without problems) and enter 1 in Choice, the program outputs all 62 possibilities, and then Windows gives the error: "Naamloos2.exe doesn't work anymore." Does anyone know a solution? Thanks in advance!

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

using namespace std;

string a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
string b = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
string c = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
string d = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
string e = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
string f = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
string g = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
string h = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
string i = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
string j = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

string generateOne(); string generateTwo(); string generateThree(); string generateFour();
string generateFive(); string generateSix(); string generateSeven(); string generateEight();
string generateNine(); string generateTen();

int main()
{
    SetConsoleTitle("Random-Password-Generator");
    int Choice = 0;
    
    cout << "Welcome! I'll make for you a bunch of random passwords.\n";
    cout << "Enter how long your password must be (max 10): ";
    cin >> Choice;
    cout << "Possible passwords:\n\n";
    
    switch(Choice)
    {
        case 1:
            generateOne();
            break;        
        default:
            return 1;
    }
}

string generateOne()
{
    for(size_t i = 0; i < a.length(); i++)
    {
        cout << a.at(i) << " ";
    }
}
1
2
3
4
    for(size_t i = 0; i < a.length(); i++)
    {
        cout << a.at(i) << " ";
    }


Because you are looping through all the character in a string here

Do you mean you want to randomly pick a character out of it?
If so you need to use random function.

As for the error message, its the first time I've ever heard of it. But Im guessing it is because you are missing
 
return 0;  //By the end of main function 
No, I want to generate every order of characters that is possible using the characters in a . Of course, passwords of one character aren't useful, but I want to use in for example generateTen() nine extra embedded for-loops, in each for-loop using another string, so that all possible orders with all that characters are generated and outputted. (sorry if you don't understand it, my English isn't good :( ). And I added return 0; , but that didn't work. I thought that functions in c++ return 0 by default.
Any other suggestions?
Fransje wrote:
I added return 0; , but that didn't work. I thought that functions in c++ return 0 by default.

The main function is an exception and will return 0; if nothing was returned. For all other functions you have to use a return statement to return a value.
Maybe the problem is that generateOne() doesn't return anything. If you don't want it to return anything you should make the return type void.
Thanks all for the replies and especially Peter87, because you were right :) Thanks!
Topic archived. No new replies allowed.