Help multiple errors

I've been stuck on this problem since forever and I really need to find the solution now T.T

This is the code after I tried doing some stuff. I got 3 errors and 2 warning.

(47) : error C2601: 'engtomo' : local function definitions are illegal
(75) : error C2046: illegal case
(108) : error C2046: illegal case
(115) : warning C4305: 'initializing' : truncation from 'const int' to 'char'
warning C4309: 'initializing' : truncation of constant value

I was told that the string engtomo was trying to define the function in the main.. So I tried closing the main() and adding it back again after the string engtomo but it seems like I can't do that. But after I did that it got down to 3 errors and 0 warning

(47) : error C2601: 'engtomo' : local function definitions are illegal
(74) : error C2601: 'main' : local function definitions are illegal
(158) : fatal error C1004: unexpected end of file found
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
string engtomo (string, string[]);


int main()
{
    char choice;

   do{
    cout<<"Cryptic Codes Generator"<<endl;
    cout<<"Welcome, what code do you want?";
    cout<<"1-Morse Code"<<endl;
    cout<<"2-Caesar Cipher"<<endl;
    cout<<"3-Grid Code"<<endl;
	cout<<"4-Exit";
    cin>>choice;


    switch(choice)

    case '1':
    {
        string morse[26] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
        string alpha;
        char again='3';
 
        while (again=='3')
            {
    
                {
		            cout<<"Use the English alphabet ONLY"<<endl;
                    cout << "Type the word/s you want to translate: "<<endl;
                    cin.get();
                    getline(cin,alpha);
                    cout << "TEXT: " << alpha << endl;
                    cout << "MORSE CODE: " << engtomo(alpha, morse) << endl;
                }
                cout << "Do you want to try again?"<<endl;
	            cout<<"Press 3 if you want to try again?"<<endl<<"Press any key, otherwise"<<endl;
	            cout<<"Choice:"<<endl;
                cin >> again;
	            system("CLS");
            }
    }    
}
    
   string engtomo (string alpha, string morse[]) //this string engtomo
   {     //error(47) local definitions are illegal
            int alphalength = alpha.length();
            
            string morsevalue;
            string spaceletters= " ";
            string spacewords = "  ";//2 spaces because im going to add it with spaceletters so that it will be = 3
            
            for (int a=0; a<alphalength; a++)
            {
                if (alpha[a]!= ' ')
                {
                    alpha[a]=toupper(alpha[a]); //for Uppercase and Lowercase... They have the same morse codes
                    morsevalue=spaceletters+=morse[alpha[a]-'A']+" ";
                }
                if (alpha[a]==' ')
                {
                    spaceletters+=spacewords;//for spaces
                }
             {
            return morsevalue;
			 }
			  break;
			}
   }


     //tried ading another int main() here but couldn't do that because of

    //{ << added this too
  
    case '2': //error (75)
    {
	    cout<<"Welcome to Caesar Cipher Generator"<<endl<<endl;
	    cout<<"Remember to only use lowercase letters"<<endl<<endl;
	    string input;
	    
	    int count = 0, length;
	    cout<<"Please enter your word/s here:";
	    getline(cin, input); //so you could input all characters
        length =(int)input.length();

	    for (count = 0; count < length; count++)
	    {
		    if (isalpha(input[count]))
		    {
			//13 is half the number of the alphabets
			    for (int i = 0; i<13; i++)
			    {
				    if(input[count] =='z')
					    input[count] = 'a';
				    else
					    input[count]++;
		        }
            }

	   }
        cout<<"Translated word/s:"<<input<<endl;
        system("pause");
    
	}
	

    case '3': //error(108)
	{
        char grid[6][6] = 
	    {
	        {' ','1','2','3','4','5'},
	        {'A','A','B','C','D','E'},
	        {'B','F','G','H','IJ','K'}, //this error 115
	        {'C','L','M','N','O','P'},
	        {'D','Q','R','S','T','U'},
	        {'E','V','W','X','Y','Z'},
	    };
	    char character='G';
	    int position[2] = {2,2};
        
        for (int k =0; k < 6; k ++)
	    {
		    for (int m =0; m < 6; m++)
		    {
			    if (k == position[0] && m == position[1])
				    cout << character;
			    else
				    cout << grid[k][m];
			        cout << " ";
		      }
		            cout << endl;
	    }
            
        cout << "Got your secret code?"<<endl<<endl;
	    cout<<"Press [ENTER] to end";cin.get();
	    position[1] = 1;
        system("cls");
	            
	    for (int i =0; k < 6; k ++)
	    {
		    for (int m =0; m < 6; m++)
		    {
		        if (k == position[0] && m == position[1])
				    cout << character;
			    else
				    cout << grid[k][m];
			        cout << " ";
		    }
		            cout << endl;
	   }

       cout << "\n\nThank you for using Crptic Codes Generator."; cin.get();
       system("CLS");        
	}
	break;
        } while (choice!='4')
         return 0;
}






Well here my first code that got 2 errors
(48) : error C2601: 'engtomo' : local function definitions are illegal
(152) : fatal error C1004: unexpected end of file found

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
string engtomo (string, string[]);


int main()
{
    char choice;
    cout<<"Cryptic Codes Generator"<<endl;
    cout<<"Welcome, what code do you want?";
    cout<<"1-Morse Code"<<endl;
    cout<<"2-Caesar Cipher"<<endl;
    cout<<"3-Grid Code"<<endl;
	cout<<"4-Exit";
    cin>>choice;


    switch(choice)

    case '1':
    {
        string morse[26] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
        string alpha;
        char again='3';
 
        while (again=='3')
            {
    
                {
		            cout<<"Use the English alphabet ONLY"<<endl;
                    cout << "Type the word/s you want to translate: "<<endl;
                    cin.get();
                    getline(cin,alpha);
                    cout << "TEXT: " << alpha << endl;
                    cout << "MORSE CODE: " << engtomo(alpha, morse) << endl;
                }
                cout << "Do you want to try again?"<<endl;
	            cout<<"Press 3 if you want to try again?"<<endl<<"Press any key, otherwise"<<endl;
	            cout<<"Choice:"<<endl;
                cin >> again;
	            system("CLS");
            }
    }    

    
   string engtomo (string alpha, string morse[])
   {     //error 48
            int alphalength = alpha.length();
            
            string morsevalue;
            string spaceletters= " ";
            string spacewords = "  ";//2 spaces because im going to add it with spaceletters so that it will be = 3
            
            for (int a=0; a<alphalength; a++)
            {
                if (alpha[a]!= ' ')
                {
                    alpha[a]=toupper(alpha[a]); //for Uppercase and Lowercase... They have the same morse codes
                    morsevalue=spaceletters+=morse[alpha[a]-'A']+" ";
                }
                if (alpha[a]==' ')
                {
                    spaceletters+=spacewords;//for spaces
                }
             {
            return morsevalue;
    }

    case '2':
    {
	    cout<<"Welcome to Caesar Cipher Generator"<<endl<<endl;
	    cout<<"Remember to only use lowercase letters"<<endl<<endl;
	    string input;
	    
	    int count = 0, length;
	    cout<<"Please enter your word/s here:";
	    getline(cin, input); //so you could input all characters
        length =(int)input.length();

	    for (count = 0; count < length; count++)
	    {
		    if (isalpha(input[count]))
		    {
			//13 is half the number of the alphabets
			    for (int i = 0; i<13; i++)
			    {
				    if(input[count] =='z')
					    input[count] = 'a';
				    else
					    input[count]++;
		        }
            }
	   }
        cout<<"Translated word/s:"<<input<<endl;
        system("pause");
    }
    
    case '3':
	{
        char grid[6][6] = 
	    {
	        {' ','1','2','3','4','5'},
	        {'A','A','B','C','D','E'},
	        {'B','F','G','H','I','J','K'},
	        {'C','L','M','N','O','P'},
	        {'D','Q','R','S','T','U'},
	        {'E','V','W','X','Y','Z'},
	    }
	    char character='G';
	    int position[2] = {2,2};
        
        for (int k =0; k < 6; k ++)
	    {
		    for (int m =0; m < 6; m++)
		    {
			    if (k == position[0] && m == position[1])
				    cout << character;
			    else
				    cout << grid[k][m];
			        cout << " ";
			}
		            cout << endl;
	    }
            
        cout << "Got your secret code?"<<endl<<endl;
	    cout<<"Press [ENTER] to end";cin.get();
	    position[1] = 1;
        system("cls");
	            
	    for (int i =0; k < 6; k ++)
	    {
		    for (int m =0; m < 6; m++)
		    {
		        if (k == position[0] && m == position[1])
				    cout << character;
			    else
				    cout << grid[k][m];
			        cout << " ";
		    }
		            cout << endl;
	   }

       cout << "\n\nThank you for using Crptic Codes Generator."; cin.get();
             
	}break;
	while (choice!='4')
		return 0;
			}
}//error 143 



Need help badly...
The output should be

Cryptic Codes Generator
Welcome, what code do you want?
1-Morse Code
2-Caesar Cipher
3-Grid Code
4-Exit


if 1
Use the english alphabet only
Type word/s you want to translate: //dog

Text: Dog
Morse Code: -.. --- --.
Do you want to try again?
Press 3 if you want to try again
Press any key, otherwise
Choice:

if 2

Welcome to Caesar Cipher Generator

Remember to only use lowercase letters

Please enter your word/s here://dog

translated word/s: qbt

if 3

1 2 3 4 5
A A B C D E
B F G H IJ K
C L M N O P
D Q R S T U
E V W X Y Z
Got your secret code?
Press [Enter] to end
//enter
Thank you for using Cryptic codes generator

Last edited on
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// ConsoleApplication9.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <cctype>
#include <string>

using namespace std;


string engtomo(string alpha, string morse[])
{ 
	int alphalength = alpha.length();

	string morsevalue;
	string spaceletters = " ";
	string spacewords = "  ";//2 spaces because im going to add it with spaceletters so that it will be = 3

	for (int a = 0; a < alphalength; a++)
	{
		if (alpha[a] != ' ')
		{
			alpha[a] = toupper(alpha[a]); //for Uppercase and Lowercase... They have the same morse codes
			morsevalue = spaceletters += morse[alpha[a] - 'A'] + " ";
		}
		if (alpha[a] == ' ')
		{
			spaceletters += spacewords;//for spaces
		}
		return morsevalue;
	}
}

int main()
{
	int choice;
	string morse[26] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.." };
	string alpha;
	string input;
	char again;
	int count = 0, length;
	do {
	cout << "Cryptic Codes Generator" << endl;
	cout << "Welcome, what code do you want?" << endl;
	cout << "1-Morse Code" << endl;
	cout << "2-Caesar Cipher" << endl;
	cout << "3-Grid Code" << endl;
	cout << "4-Exit" << endl;
	cin >> choice;
	
	switch (choice) {

	case 1:
		again = '3';
		while (again == '3')
		{
			cout << "Use the English alphabet ONLY" << endl;
			cout << "Type the word/s you want to translate: " << endl;
			cin.get();
			getline(cin, alpha);
			cout << "TEXT: " << alpha << endl;
			cout << "MORSE CODE: " << engtomo(alpha, morse) << endl;

			cout << "Do you want to try again?" << endl;
			cout << "Press 3 if you want to try again?" << endl << "Press any key, otherwise" << endl;
			cout << "Choice:" << endl;
			cin >> again;
			system("CLS");
		}
	break;


	case 2:
		cout << "Welcome to Caesar Cipher Generator" << endl << endl;
		cout << "Remember to only use lowercase letters" << endl << endl;

		count = 0;
		cout << "Please enter your word/s here:";
		getline(cin, input); //so you could input all characters
		length = (int)input.length();

		for (count = 0; count < length; count++)
		{
			if (isalpha(input[count]))
			{
				//13 is half the number of the alphabets
				for (int i = 0; i < 13; i++)
				{
					if (input[count] == 'z')
						input[count] = 'a';
					else
						input[count]++;
				}
			}
		}
		cout << "Translated word/s:" << input << endl;
		system("pause");
	break;

	case 3:
		char grid[6][6] =
		{
			{ ' ','1','2','3','4','5' },
			{ 'A','A','B','C','D','E' },
			{ 'B','F','G','H','I','J' }, //,'K' i removed that becouse you set array for 6
			{ 'C','L','M','N','O','P' },
			{ 'D','Q','R','S','T','U' },
			{ 'E','V','W','X','Y','Z' },
		};

		char character = 'G';
		int position[2] = { 2,2 };

		for (int k = 0; k < 6; k++)
		{
			for (int m = 0; m < 6; m++)
			{
				if (k == position[0] && m == position[1])
					cout << character;
				else
					cout << grid[k][m];
				cout << " ";
			}
			cout << endl;
		}

		cout << "Got your secret code?" << endl << endl;
		cout << "Press [ENTER] to end"; cin.get();
		position[1] = 1;
		system("cls");

		for (int k = 0; k < 6; k++)
		{
			for (int m = 0; m < 6; m++)
			{
				if (k == position[0] && m == position[1])
					cout << character;
				else
					cout << grid[k][m];
				cout << " ";
			}
			cout << endl;
		}

		cout << "\n\nThank you for using Crptic Codes Generator."; cin.get();

	break;
	}

	}while (choice != 4);
	return 0;
}
Last edited on
In case 3: i removed "k" from your array because you set it to [6][6] in 1 row it was [7].

In switch case method you dont have to use braces in cases. Only one is needed in switch that contains all cases.
After every case there should be break; so your chosen case doesn't slip to other cases.

Also never initialize any variables inside loops.
Last edited on
Topic archived. No new replies allowed.