Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 4-5 Enumerated types.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include "string"
- //Define an enumerated type to choose between the following monster races: orcs, goblins, trolls, ogres, and skeletons.
- //Define a variable of the enumerated type you defined in question 1 and assign it the troll enumerator.
- enum class MonsterType
- {
- ORC,
- GOBLIN,
- TROLL,
- OGRE,
- SKELETON,
- BEAST
- };
- std::string getMonsterType(MonsterType monsterType)
- {
- using std::string;
- if (monsterType == MonsterType::ORC)
- return string("Orc");
- if (monsterType == MonsterType::GOBLIN)
- return string("Goblin");
- if (monsterType == MonsterType::TROLL)
- return string("Troll");
- if (monsterType == MonsterType::OGRE)
- return string("Ogre");
- if (monsterType == MonsterType::SKELETON)
- return string("Skeleton");
- if (monsterType == MonsterType::BEAST)
- return string("Beast");
- return string("Unknown");
- }
- int main()
- {
- using std::cout;
- using std::endl;
- MonsterType currentEnemyMonsterType;
- cout << "You face a hill troll!" << endl;
- currentEnemyMonsterType = MonsterType::TROLL;
- cout << "This monster is of the type: " << getMonsterType(currentEnemyMonsterType) << endl;
- cout << "You kill the hill troll. But suddenly, a lich jumps out from behind the bushes!" << endl;
- currentEnemyMonsterType = MonsterType::SKELETON;
- cout << "This monster is of the type: " << getMonsterType(currentEnemyMonsterType) << endl;
- cout << "The lich is anemic from not consuming enough souls and collapses on the spot. You instead try to fight a nearby dire squirrel." << endl;
- currentEnemyMonsterType = MonsterType::BEAST;
- cout << "This monster is of the type: " << getMonsterType(currentEnemyMonsterType) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement