How to get an array from a function?

I'm writing a practice program. The final function tells the user if he/she
has a good set of initials, which really doesn't mean anything, just practice.
I need to use arrays of letters for the initials of the user's first, middle,
and last name, which are in a different function and I don't know how to get those over to this other 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
67
68
69
70
71
72
  /*
Create list of letters for first, middle, and last
    name that can make up a good match
Get first, middle, and last name.
Display whole name.
Store initials in another variable
Show how many letters are in each name.
If all initials are in the lists
    tell user that their initials are a good match
else
    tell user that their initials are not a good match
*/

#include <iostream>
#include <string>

using namespace std;


void goodLetters();      // list of good initials for each name
string name(string fml); // get a name to return to first, middle, or last
void goodOrBad(const char& f, const char& m, const char& l);      // tell user if they have good initials

int main()
{
    void goodLetters();

    string first = name("first");
    string middle = name("middle");
    string last = name("last");

    cout << "Your full name is " << first << " " << middle << " " << last << ".\n ";

    cout << "\nYour first name has " << first.size() << " letters in it.";
    cout << "\nYour middle name has " << middle.size() << " letters in it.";
    cout << "\nYour last name has " << last.size() << " letters in it.";

    const char fInitial = first[0];
    const char mInitial = middle[0];
    const char lInitial = last[0];

    void goodOrBad(const char& fInitial, const char& mInitial, const char& lInitial);


    return 0;
}

void goodLetters()
{
    char firstNameLetters[12] = {'A', 'B', 'C', 'E', 'I', 'L', 'M', 'N', 'T', 'Y'};
    char middleNameLetters[14] = {'B', 'C', 'D', 'F', 'G', 'H', 'J', 'O', 
                                  'Q', 'X', 'V', 'W', 'Y', 'Z'};
    char lastNameLetters[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
}

string name(string fml) // fml stands for first, middle, last
{
    string temp;
    cout << "What is your " << fml << " name? .-*:";
    cin >> temp;
    return temp;
}




void goodOrBad(const char& f, const char& m, const char& l)
{
    for (int i = 0; i < 12; ++i) // here's where I'm not sure how to get the arrays

} 
closed account (28poGNh0)
I hope that what you're looking for

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
# include <iostream>
# include <string>
using namespace std;

string name(string fml);
int goodOrBad(const char f, const char m, const char l);

int main()
{
    // void goodLetters();This is a function prototype declaration,please dont do it here

    string first = name("first");
    string middle = name("middle");
    string last = name("last");

    cout << "Your full name is " << first << " " << middle << " " << last << ".\n ";

    cout << "\nYour first name has " << first.size() << " letters in it." << endl;
    cout << "\nYour middle name has " << middle.size() << " letters in it." << endl;
    cout << "\nYour last name has " << last.size() << " letters in it." << endl;

    const char fInitial = first[0];
    const char mInitial = middle[0];
    const char lInitial = last[0];

    switch(goodOrBad(fInitial,mInitial,lInitial))
    {
    case 0:
        cout << "Everything is good" << endl;
        break;
    case 2:
        cout << "First is bad........." << endl;
        break;
    case 3:
        cout << "Midle is bad........." << endl;
        break;
    case 4:
        cout << "last is bad.........." << endl;
        break;
    }


    return 0;
}

string name(string fml) // fml stands for first, middle, last
{
    string temp;
    cout << "What is your " << fml << " name? .-*:";
    cin >> temp;
    return temp;
}

int goodOrBad(const char f, const char m, const char l)
{
    char firstNameLetters[12] = {'A', 'B', 'C', 'E', 'I', 'L', 'M', 'N', 'T', 'Y'};
    char middleNameLetters[14] = {'B', 'C', 'D', 'F', 'G', 'H', 'J', 'O',
                                  'Q', 'X', 'V', 'W', 'Y', 'Z'};
    char lastNameLetters[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

    for(int i=0;i<12;i++)
    {
        if(f!=firstNameLetters[i])
            return 2;
    }

    for(int i=0;i<14;i++)
    {
        if(f!=middleNameLetters[i])
            return 3;
    }

    for(int i=0;i<26;i++)
    {
        if(f!=lastNameLetters[i])
            return 4;
    }
    return 0;
}
Yes, thank you.
Topic archived. No new replies allowed.