gpt4 book ai didi

c++ - 不断收到错误: expected unqualified id at end of input- C++

转载 作者:行者123 更新时间:2023-12-02 11:13:58 25 4
gpt4 key购买 nike

当我尝试运行代码时,总是出现在最后一行,因此我一直收到此错误。我正在尝试制作基于文本的冒险游戏。似乎(当我运行此命令时)这是我唯一的错误。但是,如果有更多人注意到您的帮助,将不胜感激。

所以我的问题是:(1)这到底是什么意思,(2)我如何解决它,以及(3)将来如何避免这种情况?

只是警告:此代码有800多行,因此请尽量采取。

编辑:好的,我已经从以前弄清楚了问题,但是,现在我类中的语句将不会输出。我类(class)中的“cout”语句(例如,fairy()类)以及房间标题和描述都将跳过。我将代码重新排列了一下。

    //Chandler Witthaus
//Final Project- Text Adventure
//Professor Caleb Fowler
//17 December 2016

#include <iostream>
#include <string>
#include <stdlib.h>

int playerGold,
findDirect,
exitN,
exitS,
exitE,
exitW;

std::string start,
direction,
roomName,
roomDiscription;

using namespace std;

class Monster {
public:
void fairy() {
std::string monEncounter = "A fairy is stuck in a discarded can. You let her out and she rewards you with 5 gold.\n";
playerGold = playerGold + 5;
}
void unicorn() {
std::string monEncounter = "You see a unicorn frolicking in this room. The animal stares at you for a moment "
"before pointing its horn at a sack on the floor containing 20 gold.\n";
playerGold = playerGold + 20;
}
void nymph() {
std::string monEncounter = "A beautiful nymph approached you, she offers you 100 gold for a brief fling. You are "
"reminded of your college days but hastily accept.\n";
playerGold = playerGold + 100;
}
void imp() {
std::string monEncounter = "A little imp runs by, snatching 2 gold from your pouch. He disappears before you are able to catch him.\n";
playerGold = playerGold - 2;
}
void wisp() {
std::string monEncounter = "A will-o'-the-wisp entices you to follow it. You bang into a wall, dropping your gold pouch. You pick it back "
"up but are unable to find 10 pieces.\n";
playerGold = playerGold - 10;
}
void goblin() {
std::string monEncounter = "A greedy goblin ambushes you. You fight him off, but not before he takes 15 gold.\n";
playerGold = playerGold - 15;
}
void centaur() {
std::string monEncounter = "You encounter a wild centaur, who is bucking wildly. You try to sneak around him but are struck, losing 20 gold.";
playerGold = playerGold - 20;
}
void wraith() {
std::string monEncounter = "Upon entering you are confronted by a wraith. It throws a curse on you, but thinking fast, you "
"eat 50 gold pieces. This makes the wraith very uncomfortable, it quickly removes the curse and leaves without "
"making eye contact.\n";
playerGold = playerGold - 50;
}
void cyclops() {
std::string monEncounter = "You encounter a massive cyclops, he attempts to eat you. However, acting quickly, you make "
"a replica of yourself out of 80 gold pieces. The cyclops eats the replica and chokes to "
"death. You are not willing to recover the gold.\n";
playerGold = playerGold - 80;
}
void hydra() {
std::string monEncounter = "You encounter a massive hydra. He will let you pass for 15 gold, you begrudgingly agree. You begin "
"to walk past, but the other heads of the hydra demand their pay. The toll ends up costing 135 gold. You quietly curse the hydra.\n";
playerGold = playerGold - 135;
}
void bird() {
std::string monEncounter = "You see a bird, this must be the exit, but which way?\n";
}
};

class RandomSpawn {
public:
void spawnEnemy() {
int spawn = rand() % 10;
if (spawn <= 4) {
Monster objectImp;
objectImp.imp();
}
if (spawn == 5) {
Monster objectWisp;
objectWisp.wisp();
}
if (spawn == 6) {
Monster objectGoblin;
objectGoblin.goblin();
}
if (spawn == 7) {
Monster objectCentaur;
objectCentaur.centaur();
}
if (spawn == 8) {
Monster objectWraith;
objectWraith.wraith();
}
if (spawn == 9) {
Monster objectCyclops;
objectCyclops.cyclops();
}
if (spawn == 10) {
Monster objectHydra;
objectHydra.hydra();
}
}
};

class Treasure {
public:
void startChest() {
std::string chestType = "You find a beautiful chest. It is filled with 1000 gold. It makes you so excited that you don't even notice "
"as the entrance disappears. Looks like you will have to find your own way out.\n";
playerGold = 1000;
}
void smallChest() {
std::string chestType = "You find a small chest containing 150 gold. You feel a strong urge to shower in it, but you hold yourself back.\n";
playerGold = playerGold + 150;
}
void mediumChest() {
std::string chestType = "You find a chest with a pirate symbol on it. Ignoring it, you plunder 300 gold, feeling a thrill from the "
"steal. You think you may be a kleptomaniac.";
playerGold = playerGold + 300;
}
void largeChest() {
std::string chestType = "You find a large chest, no not that kind. You get 500 gold...dirty\n";
playerGold = playerGold + 500;
}
};

class Room {
public:
void room11() {
std::string roomName = "North-West corner";
std::string roomDiscription = "";
int roomId = 11;
Monster objectUnicorn;
objectUnicorn.unicorn();
int exitN = 0;
int exitS = 12;
int exitE = 21;
int exitW = 0;
}
void room21() {
std::string roomName = "Storage room";
std::string roomDiscription = "";
int roomId = 21;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 0;
int exitS = 22;
int exitE = 31;
int exitW = 11;
}
void room31() {
std::string roomName = "Grey room";
std::string roomDiscription = "";
int roomId = 31;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 0;
int exitS = 32;
int exitE = 41;
int exitW = 21;
}
void room41() {
std::string roomName = "Clock room";
std::string roomDiscription = "";
int roomId = 41;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 0;
int exitS = 42;
int exitE = 51;
int exitW = 31;
}
void room51() {
std::string roomName = "North-East corner";
std::string roomDiscription = "";
int roomId = 51;
Monster objectNymph;
objectNymph.nymph();
int exitN = 0;
int exitS = 52;
int exitE = 0;
int exitW = 41;
}
void room12() {
std::string roomName = "Chair room";
std::string roomDiscription = "";
int roomId = 12;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 11;
int exitS = 13;
int exitE = 22;
int exitW = 0;
}
void room22() {
std::string roomName = "Alchemy room";
std::string roomDiscription = "";
int roomId = 22;
Treasure objectLargeChest;
objectLargeChest.largeChest();
int exitN = 21;
int exitS = 23;
int exitE = 32;
int exitW = 12;
}
void room32() {
std::string roomName = "Sun room";
std::string roomDiscription = "";
int roomId = 32;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 32;
int exitS = 33;
int exitE = 42;
int exitW = 22;
}
void room42() {
std::string roomName = "Meaning of the universe room";
std::string roomDiscription = "";
int roomId = 42;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 41;
int exitS = 43;
int exitE = 52;
int exitW = 32;
}
void room52() {
std::string roomName = "Hallway";
std::string roomDiscription = "";
int roomId = 52;
Monster objectBird;
objectBird.bird();
int exitN = 51;
int exitS = 53;
int exitE = 62;
int exitW = 42;
}
void room13() {
std::string roomName = "Medical room";
std::string roomDiscription = "";
int roomId = 13;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 12;
int exitS = 13;
int exitE = 23;
int exitW = 0;
}
void room14() {
std::string roomName = "Guest bedroom";
std::string roomDiscription = "";
int roomId = 14;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 13;
int exitS = 15;
int exitE = 24;
int exitW = 0;
}
void room15() {
std::string roomName = "Guest kitchen";
std::string roomDiscription = "";
int roomId = 15;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 14;
int exitS = 16;
int exitE = 25;
int exitW = 0;
}
void room16() {
std::string roomName = "Storage room";
std::string roomDiscription = "";
int roomId = 16;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 15;
int exitS = 17;
int exitE = 26;
int exitW = 0;
}
void room17() {
std::string roomName = "Hallway";
std::string roomDiscription = "";
int roomId = 17;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 16;
int exitS = 18;
int exitE = 27;
int exitW = 0;
}
void room18() {
std::string roomName = "South-West Corner";
std::string roomDiscription = "";
int roomId = 18;
Treasure objectSmallChest;
objectSmallChest.smallChest();
Monster objectWraith;
objectWraith.wraith();
int exitN = 17;
int exitS = 0;
int exitE = 28;
int exitW = 0;
}
void room23() {
std::string roomName = "Library room";
std::string roomDiscription = "";
int roomId = 23;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 22;
int exitS = 24;
int exitE = 33;
int exitW = 13;
}
void room24() {
std::string roomName = "Washroom";
std::string roomDiscription = "";
int roomId = 24;
Treasure objectSmallChest;
objectSmallChest.smallChest();
int exitN = 23;
int exitS = 25;
int exitE = 34;
int exitW = 14;
}
void room25() {
std::string roomName = "Workshop";
std::string roomDiscription = "";
int roomId = 25;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 24;
int exitS = 26;
int exitE = 35;
int exitW = 15;
}
void room26() {
std::string roomName = "Courtyard";
std::string roomDiscription = "";
int roomId = 26;
Monster objectNymph;
objectNymph.nymph();
int exitN = 25;
int exitS = 27;
int exitE = 36;
int exitW = 16;
}
void room27() {
std::string roomName = "Garden";
std::string roomDiscription = "";
int roomId = 27;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 26;
int exitS = 28;
int exitE = 37;
int exitW = 17;
}
void room28() {
std::string roomName = "Chapel";
std::string roomDiscription = "";
int roomId = 28;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 27;
int exitS = 0;
int exitE = 38;
int exitW = 18;
}
void room33() {
std::string roomName = "Pantry";
std::string roomDiscription = "";
int roomId = 33;
Monster objectFairy;
objectFairy.fairy();
int exitN = 32;
int exitS = 34;
int exitE = 43;
int exitW = 23;
}
void room34() {
std::string roomName = "Master chambers";
std::string roomDiscription = "";
int roomId = 34;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 33;
int exitS = 35;
int exitE = 44;
int exitW = 24;
}
void room35() {
std::string roomName = "Guard house";
std::string roomDiscription = "";
int roomId = 35;
Monster objectFairy;
objectFairy.fairy();
int exitN = 34;
int exitS = 36;
int exitE = 45;
int exitW = 25;
}
void room36() {
std::string roomName = "Lavatory";
std::string roomDiscription = "";
int roomId = 36;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 35;
int exitS = 37;
int exitE = 46;
int exitW = 26;
}
void room37() {
std::string roomName = "Foyer";
std::string roomDiscription = "";
int roomId = 37;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 36;
int exitS = 38;
int exitE = 47;
int exitW = 27;
}
void room38() {
std::string roomName = "Gatehouse";
std::string roomDiscription = "";
int roomId = 38;
Treasure objectStarterChest;
objectStarterChest.startChest();
int exitN = 37;
int exitS = 0;
int exitE = 48;
int exitW = 28;
}
void room43() {
std::string roomName = "Walk-in closet";
std::string roomDiscription = "";
int roomId = 43;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 42;
int exitS = 44;
int exitE = 53;
int exitW = 33;
}
void room44() {
std::string roomName = "Sitting room";
std::string roomDiscription = "";
int roomId = 44;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 43;
int exitS = 45;
int exitE = 54;
int exitW = 34;
}
void room45() {
std::string roomName = "Great Hall";
std::string roomDiscription = "";
int roomId = 45;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 44;
int exitS = 46;
int exitE = 55;
int exitW = 35;
}
void room46() {
std::string roomName = "Kitchen";
std::string roomDiscription = "";
int roomId = 46;
Treasure objectSmallChest;
objectSmallChest.smallChest();
int exitN = 45;
int exitS = 47;
int exitE = 56;
int exitW = 36;
}
void room47() {
std::string roomName = "Buttery";
std::string roomDiscription = "";
int roomId = 47;
Monster objectUnicorn;
objectUnicorn.unicorn();
int exitN = 46;
int exitS = 48;
int exitE = 57;
int exitW = 37;
}
void room48() {
std::string roomName = "Storage room";
std::string roomDiscription = "";
int roomId = 48;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 47;
int exitS = 0;
int exitE = 58;
int exitW = 38;
}
void room53() {
std::string roomName = "Hallway";
std::string roomDiscription = "";
int roomId = 53;
Treasure objectMediumChest;
objectMediumChest.mediumChest();
int exitN = 52;
int exitS = 54;
int exitE = 0;
int exitW = 43;
}
void room54() {
std::string roomName = "Compost shed";
std::string roomDiscription = "";
int roomId = 54;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 53;
int exitS = 55;
int exitE = 0;
int exitW = 44;
}
void room55() {
std::string roomName = "Tool shed";
std::string roomDiscription = "";
int roomId = 55;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 54;
int exitS = 56;
int exitE = 0;
int exitW = 45;
}
void room56() {
std::string roomName = "Blacksmith";
std::string roomDiscription = "";
int roomId = 56;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 55;
int exitS = 57;
int exitE = 0;
int exitW = 46;
}
void room57() {
std::string roomName = "Guardroom";
std::string roomDiscription = "";
int roomId = 57;
Treasure objectMediumChest;
objectMediumChest.mediumChest();
Monster objectWisp;
objectWisp.wisp();
int exitN = 56;
int exitS = 58;
int exitE = 0;
int exitW = 47;
}
void room58() {
std::string roomName = "South-East corner";
std::string roomDiscription = "";
int roomId = 58;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 57;
int exitS = 0;
int exitE = 0;
int exitW = 48;
}
};

class Direction {
public:
void roomChanging() {
if (findDirect == 11) {
Room objectRoom11;
objectRoom11.room11();
}

if (findDirect == 12){
Room objectRoom12;
objectRoom12.room12();
}

if (findDirect == 13){
Room objectRoom13;
objectRoom13.room13();
}

if (findDirect == 14){
Room objectRoom14;
objectRoom14.room14();
}

if (findDirect == 15){
Room objectRoom15;
objectRoom15.room15();
}

if (findDirect == 16){
Room objectRoom16;
objectRoom16.room16();
}

if (findDirect == 17){
Room objectRoom17;
objectRoom17.room17();
}

if (findDirect == 18){
Room objectRoom18;
objectRoom18.room18();
}

if (findDirect == 21){
Room objectRoom21;
objectRoom21.room21();
}

if (findDirect == 22){
Room objectRoom22;
objectRoom22.room22();
}

if (findDirect == 23){
Room objectRoom23;
objectRoom23.room23();
}

if (findDirect == 24){
Room objectRoom24;
objectRoom24.room24();
}

if (findDirect == 25){
Room objectRoom25;
objectRoom25.room25();
}

if (findDirect == 26){
Room objectRoom26;
objectRoom26.room26();
}

if (findDirect == 27){
Room objectRoom27;
objectRoom27.room27();
}

if (findDirect == 28){
Room objectRoom28;
objectRoom28.room28();
}

if (findDirect == 31){
Room objectRoom31;
objectRoom31.room31();
}

if (findDirect == 32){
Room objectRoom32;
objectRoom32.room32();
}

if (findDirect == 33){
Room objectRoom33;
objectRoom33.room33();
}

if (findDirect == 34){
Room objectRoom34;
objectRoom34.room34();
}

if (findDirect == 35){
Room objectRoom35;
objectRoom35.room35();
}

if (findDirect == 36){
Room objectRoom36;
objectRoom36.room36();
}

if (findDirect == 37){
Room objectRoom37;
objectRoom37.room37();
}

if (findDirect == 38){
Room objectRoom38;
objectRoom38.room38();
}

if (findDirect == 41){
Room objectRoom41;
objectRoom41.room41();
}

if (findDirect == 42){
Room objectRoom42;
objectRoom42.room42();
}

if (findDirect == 43){
Room objectRoom43;
objectRoom43.room43();
}

if (findDirect == 44){
Room objectRoom44;
objectRoom44.room44();
}

if (findDirect == 45){
Room objectRoom45;
objectRoom45.room45();
}

if (findDirect == 46){
Room objectRoom46;
objectRoom46.room46();
}

if (findDirect == 47){
Room objectRoom47;
objectRoom47.room47();
}

if (findDirect == 48){
Room objectRoom48;
objectRoom48.room48();
}

if (findDirect == 51){
Room objectRoom51;
objectRoom51.room51();
}

if (findDirect == 52){
Room objectRoom52;
objectRoom52.room52();
}

if (findDirect == 53){
Room objectRoom53;
objectRoom53.room53();
}

if (findDirect == 54){
Room objectRoom54;
objectRoom54.room54();
}

if (findDirect == 55){
Room objectRoom55;
objectRoom55.room55();
}

if (findDirect == 56){
Room objectRoom56;
objectRoom56.room56();
}

if (findDirect == 57){
Room objectRoom57;
objectRoom57.room57();
}

if (findDirect == 58){
Room objectRoom58;
objectRoom58.room58();
}
}
};

int main()
{
cout << "Welcome\n\n";
cout << "You are playing 'Deep Delver'.\n\n";
cout << "The object of this game is to enter this old castle and emerge with as much gold as possible.\n\n";
cout << "If you lose all your gold, you lose.\n\n";
cout << "Here are the controls:\n Enter 'N', 'S', 'E', or 'W'. to go in that direction.\n";
cout << "To see the description of the room your in press 'L'.\n\nGood luck!\n\n";
cout << "Enter anything to start: ";
cin >> start;

Room objectStartingRoom;
objectStartingRoom.room38();

do {
cout << "\n\nWhich way would you like to go?\n\n";
stupid:
cout << "Cardnal direction: ";
cin >> direction;
cout << endl << endl;
if (direction == "W" || direction == "w")
findDirect = exitW;
else if (direction == "E" || direction == "e")
findDirect = exitE;
else if (direction == "N" || direction == "n")
findDirect = exitN;
else if (direction == "S" || direction == "s")
findDirect = exitS;
else if (findDirect == 0)
{
cout << "You bump into a wall...like an idiot. Go a different direction.\n\n";
goto stupid;
}
else
{
cout << "That is not a direction...stupid.\n\n";
goto stupid;
}

Direction objectDirection;
objectDirection.roomChanging();

cout << roomName << endl << endl;
cout << roomDiscription << endl << endl;
} while (exitE != 62);

cout << "\n\nCongradulations!!!\n\n";
cout << "You have found your way out with " << playerGold << " gold. Don't spend it all in one place!";
}

最佳答案

您缺少花括号。您永远不会关闭roomChanging()函数。

关于c++ - 不断收到错误: expected unqualified id at end of input- C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41008257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com