mercredi 26 avril 2017

How to convert my count value to enum as output?

This is a sample snippet.

#include <iostream>
#include <string>
using namespace std;

enum class status{
CONNECTED,
NOT_CONNECTED
};

int main(){

std::string x;
std::cout<<"Enter a binary string = ";
std::getline(std::cin,x);
int count = 0;
for (int i=0;i < x.size() ; i++){
    if(x[i] & 1)
        ++count;
}

 std::cout<<"count = " <<count <<std::endl;
 return count;
}`

I want to use the value of my count to compare and result out the enum type as an output. That is I want to do:
//pseudo: if(count == 1 ) output CONNECTED; elseif(count > 1) output DISCONNECTED;

How can this be done?

Aucun commentaire:

Enregistrer un commentaire