2015-12-08 2 views
-1

я сделал ранее нить об этом, и каким-то образом удалось получить его до 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 \ а \ 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) 
+3

Прочитайте сообщение об ошибке снова: «определения локальных функций являются незаконными». И так много других синтаксических ошибок, таких как отсутствие условия в цикле 'do ... while', отсутствие точек с запятой, отсутствие или смещение брекетов и, вероятно, намного больше. Множество логических ошибок тоже, таких как пропущенные фразы «break» в коммутационных шкафах, отсутствующие фигурные скобки вокруг списков операторов и т. Д. –

+0

Я исправил ваше форматирование как можно лучше, чтобы попытаться прочитать и понять ваш код, который появляется быть немного беспорядком. У вас проблемы с синтаксисом. 'While; cin.get() cin.get(). 'недействителен (отсутствующие точки с запятой, а' while' нуждается в выражении). «String engtomo (string alpha, string morse []) {' ​​пытается определить функцию внутри вашего 'main', что запрещено в C/C++. Функции не могут быть определены внутри функций. – lurker

+0

@ lurker может я знаю, как это предотвратить? Я попытался переместить его перед int main(), но он дал мне больше ошибок после того, как я скомпилировал его. – Kaimei

ответ

1

Вы пропускаете охватывающую } после main, поэтому он считает, что вы пытаетесь определить engtomo в main

Смежные вопросы