Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. // 4-5 Enumerated types.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include "string"
  7.  
  8. //Define an enumerated type to choose between the following monster races: orcs, goblins, trolls, ogres, and skeletons.
  9. //Define a variable of the enumerated type you defined in question 1 and assign it the troll enumerator.
  10.  
  11. enum class MonsterType
  12. {
  13. ORC,
  14. GOBLIN,
  15. TROLL,
  16. OGRE,
  17. SKELETON,
  18. BEAST
  19. };
  20.  
  21. std::string getMonsterType(MonsterType monsterType)
  22. {
  23. using std::string;
  24.  
  25. if (monsterType == MonsterType::ORC)
  26. return string("Orc");
  27. if (monsterType == MonsterType::GOBLIN)
  28. return string("Goblin");
  29. if (monsterType == MonsterType::TROLL)
  30. return string("Troll");
  31. if (monsterType == MonsterType::OGRE)
  32. return string("Ogre");
  33. if (monsterType == MonsterType::SKELETON)
  34. return string("Skeleton");
  35. if (monsterType == MonsterType::BEAST)
  36. return string("Beast");
  37.  
  38. return string("Unknown");
  39. }
  40.  
  41. int main()
  42. {
  43. using std::cout;
  44. using std::endl;
  45.  
  46. MonsterType currentEnemyMonsterType;
  47.  
  48. cout << "You face a hill troll!" << endl;
  49. currentEnemyMonsterType = MonsterType::TROLL;
  50. cout << "This monster is of the type: " << getMonsterType(currentEnemyMonsterType) << endl;
  51.  
  52. cout << "You kill the hill troll. But suddenly, a lich jumps out from behind the bushes!" << endl;
  53. currentEnemyMonsterType = MonsterType::SKELETON;
  54. cout << "This monster is of the type: " << getMonsterType(currentEnemyMonsterType) << endl;
  55.  
  56. 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;
  57. currentEnemyMonsterType = MonsterType::BEAST;
  58. cout << "This monster is of the type: " << getMonsterType(currentEnemyMonsterType) << endl;
  59.  
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement