ENUMS in C++ explained easy 📅

preview_player
Показать описание
#enums #enumerations

Enums C++ tutorial example explained
Рекомендации по теме
Комментарии
Автор

#include <iostream>

enum Day {sunday = 0, monday = 1, tuesday = 2, wednesday = 3,
thursday = 4, friday = 5, saturday = 6};

int main () {

// enums = a user-defined data type that consists
// of paired named-integer constants.
// GREAT if you have a set of potential options

Day today = friday;

switch(today){
case sunday: std::cout << "It is Sunday!\n";
break;
case monday: std::cout << "It is Monday!\n";
break;
case tuesday: std::cout << "It is Tuesday!\n";
break;
case wednesday: std::cout << "It is Wednesday!\n";
break;
case thursday: std::cout << "It is Thursday!\n";
break;
case friday: std::cout << "It is Friday!\n";
break;
case saturday: std::cout << "It is Saturday!\n";
break;
}

return 0;
}

BroCodez
Автор

Oh my, visited this channel after a while and so much new content to watch!

GREAT!

Anonymationsthecoolanimator
Автор

thanks you so much for the lecture 💜 eagerly waiting for oop leacture :)

SurajDas-ziwb
Автор

Although the point of this exercise is to use enums, here a swtich epressions is why I love them.
Enums can be difficult to iterate though, and maybe getting the sizeof(Enum) might work in C++, in C# it gets a little advanced.

Dazza_Doo
Автор

enum SheSaid {big = 7, small = 6, thin = 1, skinny = 0, oh-no = 10, get-out-of-here = 100};

Dazza_Doo
Автор

have one doubt, how to use enums in arithmetic operations?

mwssiiz
Автор

//program to display planet's info using enumeration(enums) in c++
# include<iostream>
using namespace std;

enum planets
{
Mercury, Venus, Earth, Mars,
Jupiter, Saturn, Uranus, Neptune
};

int main()
{
planets planet=Mercury;
switch(planet)
{
case Mercury: cout<<"Mercury: Closest to the Sun, approximately 58 million km.";break;
case Venus: cout<<"Venus: Second planet from the Sun, approximately 108 million km.";break;
case Earth: cout<<"Earth: Third planet from the Sun, approximately 150 million km.";break;
case Mars: cout<<"Mars: Fourth planet from the Sun, approximately 228 million km.";break;
case Jupiter: cout<<"Jupiter: Fifth planet from the Sun, approximately 779 million km.";break;
case Saturn: cout<<"Saturn: Sixth planet from the Sun, approximately 1.4 billion km.";break;
case Uranus: cout<<"Uranus: Seventh planet from the Sun, approximately 2.9 billion km.";break;
case Neptune: cout<<"Neptune: Eighth planet from the Sun, approximately 4.5 billion km.";break;
}

return 0;
}

JackEvans-hfqt
Автор

enum Variables{integer, boolean}; Other variables didn't work

TheLordfNight
Автор

#include <iostream>

enum player {Messi, Ronaldo, Neymar, Ronaldinho, Suarez, Stoichkov};


int main() {

player best = Ronaldinho;

switch(best){
case Messi: std::cout << "Messi is the best football player! \n";
break;
case Ronaldo: std::cout << "Ronaldo is the best football player! \n";
break;
case Neymar: std::cout << "Neymar is the best football player! \n";
break;
case Ronaldinho: std::cout << "Ronaldinho is the best football player! \n";
break;
case Suarez: std::cout << "Suarez is the best football player! \n";
break;
case Stoichkov: std::cout << "Stoichkov is the best football player! \n";
break;
}
switch(best){
case 0: std::cout << "Messi is the best football player! \n";
break;
case 1: std::cout << "Ronaldo is the best football player! \n";
break;
case 2: std::cout << "Neymar is the best football player! \n";
break;
case 3: std::cout << "Ronaldinho is the best football player! \n";
break;
case 4: std::cout << "Suarez is the best football player! \n";
break;
case 5: std::cout << "Stoichkov is the best football player! \n";
break;
}

return 0;
}

danaildoganov