ravesli/lesson_65/main.cpp

64 lines
1001 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* main.cpp
*
* Created on: 13 сент. 2021 г.
* Author: alexander
*/
#include <iostream>
#include <string>
enum class Race
{
OGRE, GOBLIN, SKELETON, ORC, TROLL,
};
struct Monster
{
Race type;
std::string name;
int health;
};
void printMonster(Monster &m)
{
std::cout << "This ";
if (m.type == Race::OGRE)
{
std::cout << "Ogre";
}
else if (m.type == Race::GOBLIN)
{
std::cout << "Goblin";
}
else if (m.type == Race::SKELETON)
{
std::cout << "Skeleton";
}
else if (m.type == Race::ORC)
{
std::cout << "Orc";
}
else if (m.type == Race::TROLL)
{
std::cout << "Troll";
}
std::cout << " is named " << m.name << " and has " << m.health << " health."
<< std::endl;
}
int main()
{
Monster john
{ Race::GOBLIN, "John", 170 };
Monster james
{ Race::ORC, "James", 35 };
printMonster(john);
printMonster(james);
return 0;
}