2016-07-08 2 views
-1

У меня есть 3 .cpp-файла с различными главными функциями: У меня есть эта ошибка: множественное определение «enstart()» (другой файл имеет тот же код, но основная функция называется "hunstart()"множественное определение (функция)

Итак, вот мой код:

#include <iostream> 
#include <stdlib.h> 
using namespace std; 
int enstart() 
{ 
    system("TITLE HUN Homeless Millionaire"); 
    system("COLOR 0A"); 
start: 
//VARLIB START 
    string prominput; 
    string workinput; 
    string job = "Car Washer"; 
    string bck; 
    string input1; 
    string ver = "0.0.1"; 
    string note = "The game is in a really early state, please ignore the   bugs!"; 
    string shopinput; 
    string admininput; 
    int money = 0; 
    int snk = 0; 
    int shirt = 0; 
    int jobmoney = 1; 
//VARLIB END 
    cout << "Hello, Welcome to Homeless Millionaire!" << endl; 
    cout << "Game version: " <<ver << endl; 
    cout << "Note: " <<note << endl; 
    cout << "Your money: " <<money << endl; 
    cout << "Type in a command from below!" << endl; 
    cout << "Commands:" << endl; 
    cout << "Change-log" << endl; 
    cout << "Story" << endl; 
    cout << "Creator" << endl; 
    cout << "Work" << endl; 
    cout << "Shop" << endl; 
    input1 = "null"; 
    cin >> input1; 
    if (input1 == "Story") // remove from here 
    { 
     goto Story; 
    } 
    else 
    { 
     if (input1 == "Creator") 
     { 
      goto Creator; 
     } 
     else 
     { 
      if (input1 == "Shop") 
      { 
       goto shop; 
      } 
      else 
      { 
       if (input1 == "Work") 
       { 
        goto work; 
       } 
       else 
       { 
        if (input1 == "Change-log") 
        { 
         goto chlog; 
         cout << string(20, '/n'); 
        } 
        else 
        { 
         if (input1 == "adminpanel") 
          goto admin; 
        } 
       } 
      } 
     } 
    } 
    goto start; 
Story: 
    system("CLS"); 

    cout << "The game is about a 18 year old men who went debt." << endl; 
    cout << "What did you except?" << endl; 
    cout << "Type in back to continue" << endl; 
    cout << string(21, '\n'); 
    bck = "null"; 
    cin >> bck; 
    if (bck == "back") 
    { 
     goto start; 
    } 
    goto Story; 
Creator: 
    system("CLS"); 
    cout << "The game was made by: Killer Doge (C) Karsza Levente" << endl; 
    cout << "Co-Creator and Translator: TOMI8401 (C) Deli Bence" << endl; 
    cout << "Type in back to continue" << endl; 
    bck = "null"; 
    cin >> bck; 
    if (bck == "back") 
    { 
     goto start; 
    } 
    goto start; 
shop: 
    system("CLS"); 

    cout << "Welcome to the shop!" << endl; 
    cout << "Your bank account: " <<money << endl; 
    cout << "How to buy: Write in the codes of the selected item!" << endl; 
    cout << "  ITEM  | PRICE | CODE " << endl; 
    cout << " Uniform | 10 $ | UNIF " << endl; 
    cout << " Sneakers | 25 $ | SNEK " << endl; 
    cout << " Trainers | 35 $ | TRAN " << endl; 
    cout << "Better Uniform| 50 $ | BUNI " << endl; 
    cout << " Shirt  | 50 $ | SHRT " << endl; 
    cout << " Elegant Shoes| 65 $ | ESHO " << endl; 
    cout << " Cheap Phone | 85 $ | PHON " << endl; 
    shopinput = "null"; 
    cin >> shopinput; 
    if (shopinput == "SNK") 
    { 
     money -= 25; 
     snk = 1; 
     goto succb; 
    } 
    else 
    { 
     if (shopinput == "SHRT") 
     { 
      money -= 50; 
      shirt = 1; 
      goto succb; 
     } 
    } 
    goto shop; 
work: 
    system("CLS"); 

    cout << "Your current job: " <<job << endl; 
    cout << "Your salary is: " <<jobmoney << endl; 
    cout << "Your money is: " <<money << endl; 
    cout << "Commands:" << endl; 
    cout << "Promote(BUGGY)" << endl; 
    cout << "Work" << endl; 
    cout << "Back" << endl; 
    cout << string(18, '\n'); 
    workinput = "null"; 
    cin >> workinput; 
    if (workinput == "Promote") 
    { 
     goto promote; 
    } 
    else 
    { 
     if (workinput == "Work") 
     { 
      money += jobmoney; 
      goto work; 
     } 
    } 
    cin.get(); 
    goto start; 
succb: 
    system("CLS"); 
    cout << "You successfully bought this item!" << endl; 
    cout << "Your balance:" <<money << endl; 
    cout << "Type in back to continue!" << endl; 
    bck = "non"; 
    cin >> bck; 
    if (bck == "back") 
    { 
     goto start; 
    } 
    goto start; 
promote: 
    system("CLS"); 
    cout << string(20, '/n'); 
    cout << "Type in JobInfo for more information!" << endl; 
    cout << "Type in OK to try to get a promotion!" << endl; 
//continue this 
    cin.get(); 
    goto start; 
stat: 
    system("CLS"); 
    cout << "Your stats:" << endl; 
    cout << "SNK "<<snk << endl; 
    cout << "SHRT "<<shirt << endl; 
    cout << "JOB "<<job << endl; 
    cout << "MONEY "<<money << endl; 
    cout << "JOBMONEY "<<jobmoney << endl; 
    bck = "null"; 
    cin >> bck; 
    if (bck == "back") 
    { 
     goto start; 
    } 
    goto stat; 
chlog: 
    system("CLS"); 
    cout << "CHLOGTARTALOM" << endl; 
    cout << "Type in back for main menu!" << endl; 
    bck = "null"; 
    cin >> bck; 
    if (bck == "back") 
    { 
     goto start; 
    } 
    goto chlog; 
admin: 
    system("CLS"); 
    cout << "Admin panel:" << endl; 
    cout << "Type in your password!" << endl; 
    cin >> admininput; 
    if (admininput == "hmalphabranch") 
    { 
     goto adminpanel; 
    } 
    else 
    { 
     goto start; 
    } 
adminpanel: 
    system("CLS"); 
    cout << "You can't do nothing here" << endl; 
} 
+3

Пожалуйста, не используйте 'goto'. Могут быть моменты, когда это необходимо, но это не так. простые циклы и функции будут делать то, что вам нужно. – NathanOliver

+2

Как только вы разрешите эту ошибку, я надеюсь, вы не захотите отладить ее со всеми этими вызовами «goto». См. [Код спагетти] (https://en.wikipedia.org/wiki/Spaghetti_code) – PaulMcKenzie

+0

«3 cppfiles» по сравнению с «другим файлом». Это 3 или 2? И почему у вас есть тот же код в двух разных файлах cpp? –

ответ

0

Если у вас есть несколько определений функции с именем enstart, вы можете исправить это

  • , используя разные имена, или

  • размещение их в именованных пространствах имен.

Кстати, '/n' не обозначает символ новой строки. Это многобайтовая константа символа, с определенным значением реализации. Напишите '\n', где вы хотите символ новой строки.


В других новостях:

  • goto к метке ранее в коде, как правило, соответствует петле. Посмотрите на for, while и do Петли.

  • A goto к блоку кода, который заканчивается goto назад, обычно соответствует вызову функции. Вы уже знаете, как определить простые функции. Просто используйте их вместо помеченных блоков кода.

  • Бесплатные инструменты, такие как AStyle, могут помочь вам отформатировать код с правильным отступом, автоматически. Многие редакторы также могут это сделать. Я использовал AStyle для форматирования вашего кода в вопросе.

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