mercredi 27 mai 2020

Passing in enum parameter value to function C++

I have an enum defined as

enum daysOfTheWeek
{
 MONDAY,
 TUESDAY,
 WEDNESDAY,
 THURSDAY,
 FRIDAY,
}

and a function that gets the price of an item based on the day of the week

void GetPriceOfTheItem(daysOfTheWeek currentDay)
{

}

Somewhere in the code, I am running a for loop like this :

for (long day = MONDAY; day < FRIDAY ; day ++)
{
 if (day == Tuesday || day == Friday)
 { 
   GetPriceOfTheItem(day);
 }

My problem is that I can not pass day to the function, as it is incomaptible with parameter of type daysOfTheWeek, which makes sense, but I was wondering how could I do what I'm trying, without specifically passing in both Tuesday and Friday

Aucun commentaire:

Enregistrer un commentaire