У меня есть 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;
}
Пожалуйста, не используйте 'goto'. Могут быть моменты, когда это необходимо, но это не так. простые циклы и функции будут делать то, что вам нужно. – NathanOliver
Как только вы разрешите эту ошибку, я надеюсь, вы не захотите отладить ее со всеми этими вызовами «goto». См. [Код спагетти] (https://en.wikipedia.org/wiki/Spaghetti_code) – PaulMcKenzie
«3 cppfiles» по сравнению с «другим файлом». Это 3 или 2? И почему у вас есть тот же код в двух разных файлах cpp? –