2016-12-07 1 views
-4

Ich bekomme diesen Fehler, wenn ich versuche, meinen Code zu laufen, und immer auf der allerletzten Zeile. Ich versuche ein textbasiertes Abenteuerspiel zu machen. Es erscheint (wenn ich das hier ausführe), dass dies mein einziger Fehler ist. Aber wenn es mehr gibt, die irgendjemand von euch bemerkt, würde die Hilfe geschätzt werden.Keep bekommen Fehler: erwartete unqualifizierte ID am Ende der Eingabe-C++

Also meine Fragen sind: (1) Was genau bedeutet das, (2) wie repariere ich es, und (3) wie vermeide ich das in der Zukunft?

Nur eine Warnung: Dieser Code hat 800 + Zeilen, also nehmen Sie das wie Sie wollen.

EDIT: Ok, ich habe das Problem von vorher herausgefunden, aber jetzt werden die Anweisungen in meinen Klassen nicht ausgegeben. Die 'cout'-Anweisungen in meinen Klassen (zum Beispiel die Klasse fairy()) überspringen einfach, ebenso der Raumtitel und die Beschreibung. Ich habe den Code ein wenig umgeordnet.

//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!"; 
} 
+0

'while (EXITE = 62!);'? – Iluvatar

+0

@Iluvatar das ist wahrscheinlich ein Fehler, aber es ist kein Compiler Fehler – Erix

+0

fehlende Klammer am Ende von 'roomChanging()' Funktion – Yousaf

Antwort

1

Sie vermissen eine geschweifte Klammer. Sie schließen nie die roomChanging() Funktion.

+0

Verwenden Sie 'clang-format', um Ihren Code ständig für Sie aufzuräumen und diese Art von Sache wird offensichtlich sein :) –

1

Dieser Code ist ziemlich ungewöhnlich. Kennen Sie den Umfang?

void foo() { 
    Widget w; // create a widget which exists inside function foo() 
} // w is now destroyed 

Viele Ihrer Funktionen tun nichts

void room11() { 
    std::string roomName = "North-West corner"; // gets destroyed at } 
    std::string roomDiscription = "";   // gets destroyed at } 
    int roomId = 11;       // gets destroyed at } 
    Monster objectUnicorn; // does something before being destroyed at } 
    objectUnicorn.unicorn(); // increases player's gold 
    int exitN = 0;   // gets destroyed at } 
    int exitS = 12;   // gets destroyed at } 
    int exitE = 21;   // gets destroyed at } 
    int exitW = 0;   // gets destroyed at } 
} // poof! Nearly everything is destroyed without doing anything 

Ein üblicher Weg, um das Konzept eines Raumes in einer Klasse zu beschreiben wäre:

class Room { 
private: 
    int id_; 
    std::string name_; // there's a few naming conventions; one is a trailing 
    std::string desc_; // underscore for private class data members 
    // forget the monster and exits for the moment 

public: 
    Room(int id, const std::string &name, const std::string &desc) 
     : id_(id), name_(name), desc_(desc) {} 
    int id() {return id_;} 
    std::string name() {return name_;} 
    std::string desc() {return desc_;} 
}; 

Dies sagt dass jedes Zimmer einen Namen, eine Beschreibung und eine ID hat. Dann Räume zu schaffen, die Sie tun dies:

Room room11(11, "North-West corner", "The corners are sharp on the eyes."); 
Room room21(21, "Storage room", "It's full of dust and boxes."); 
Room room31(31, "Grey room", "Tell my wife, hello.") 

cout << room31.desc(); // outputs "Tell my wife, hello" 

, die ohnehin die Anfänge der Verwendung von Klassen ist ...

+0

Bingo. Nicht, was OP gefragt hat, aber auf lange Sicht viel nützlicher als "Sie haben es vermisst". [Link zur Erklärung des Umfangs.] (Https://en.wikipedia.org/wiki/Scope_ (computer_science)) – user4581301

+0

Danke, def mehr hilfreich beim Verständnis meiner Fuck-ups insgesamt. Aber gibt es eine Möglichkeit, dieses Programm zu speichern, ohne alles neu zu schreiben? –

Verwandte Themen