enum help!

hey all, just started c++ and got a bit of a problem with a piece of code i wrote
if i put it all in one function (main) it works a charm, but soon as i move it around 2 serperate functions (as i have to do :( ) i get a problem where my value is not passed to my last function

ne how here is the chunk of my code that isnt workin
cheers




#include



using namespace std;


enum Day {Sun=1,Mon,Tues,Wed,Thurs,Fri,Sat};

void GetDay(Day &D);

void PrintDay(Day D);





int main ()

{









Day D;



GetDay (D);

PrintDay(D);







return 0;

}



void GetDay(Day &D)

{



cout << "Please Select The Day From The List Bewlow: " << endl;



cout << "(1) Sunday " << endl

<< "(2) Monday " << endl

<< "(3) Tuesday " << endl

<< "(4) Wednesday " << endl

<< "(5) Thursday " << endl

<< "(6) Friday " << endl

<< "(7) Saturday " << endl;

cin >> static_cast (D);



cout << endl;



}





void PrintDay(Day D)

{

switch (D)

{

case Sun : cout << "Sunday" << endl;

break;

case Mon : cout << "Monday" << endl;

break;

case Tues : cout << "Tuesday" << endl;

break;

case Wed : cout << "Wednesday" << endl;

break;

case Thurs: cout << "Thursday" << endl;

break;

case Fri : cout << "Friday " << endl;

break;

case Sat: cout << "Saturday " << endl;

break;

}







}


Comments

  • >>cin >> (int&)D;

    you need to cast it to a reference because D is a reference.
  • : >>cin >> (int&)D;
    :
    : you need to cast it to a reference because D is a reference.
    :
    kool thank you stacks

    i figured out another way any how
    cin >> temp
    D = Day(temp)

    works

    ty anyhow
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion