我有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;
}
答案 0 :(得分:0)
如果您对名为enstart
的函数有多个定义,则可以通过
使用不同的名称,或
将它们放在不同名称的命名空间中。
顺便说一句,'/n'
并不表示换行符。它是一个多字节字符常量,具有实现定义的值。将'\n'
写在您想要换行符的位置。
在其他新闻中:
代码前面的标签goto
通常对应于循环。查看for
,while
和do
循环。
goto
到以goto
后面结尾的代码块,通常对应于函数的调用。您已经知道如何定义简单的函数。只需使用它们而不是标记的代码块。
AStyle等免费工具可以帮助您自动格式化代码并进行适当的缩进。许多编辑也可以这样做。我使用AStyle在问题中格式化你的代码。