我的程序的代码错误

时间:2015-12-08 13:31:02

标签: c++ compiler-errors

我做了一个关于它的早期帖子,并以某种方式设法将其归结为2个错误

#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" << endl;
        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 is the error
            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();
                    return 0;
                }
            }
            while;
            cin.get()
            cin.get()
        }    // this is the error

现在这两个错误是

C:\ Users \ a \ Desktop \ c ++ \ error.cpp(50):错误C2601:'engtomo':本地函数定义是非法的

C:\ Users \ a \ Desktop \ c ++ \ error.cpp(154):致命错误C1004:发现意外的文件结尾

    string engtomo (string alpha, string morse[])
   {  //This curly brace (local function definitions are illegal)

            }while;
                cin.get()
                cin.get()

    } //This curly brace too (unexpected end of file found)

1 个答案:

答案 0 :(得分:1)

您在}之后错过了封闭的main,因此它认为您要在engtomo

中定义main