big newbie here and just trying to intensely study each little bit of code i write to figure out why and how things are happening, as that's just how I learn best.
In an attempt to understand why and when to put variables inside a function's parameters rather than establishing them inside the function itself, I tried out the code below:
string dayOfWeek(){
string dayName;
int dayNum = 3;
switch(dayNum){
case 0:
dayName = "Sunday";
break;
case 1:
dayName = "Monday";
break;
case 2:
dayName = "Tuesday";
break;
case 3:
dayName = "Wednesday";
break;
case 4:
dayName = "Thursday";
break;
case 5:
dayName = "Friday";
break;
case 6:
dayName = "Saturday";
break;
default:
dayName = "invalid day number";
}
return dayName;
}
int main()
{
cout << dayOfWeek;
return 0;
}
I'm wondering why it prints 1? I am under the impression it should print "Wednesday", since I declared that dayNum = 3
, and in the case of it being 3, it would mean that dayName = "Wednesday"
. Any pointers? Thanks.