enum data types in switch statement c++ -
Bears with me first, I'm a noob
I was trying to write a program that Outputs in weekdays. Say for example, if someone enters Day 1 then this happens on Sundays, 2 days Monday and so on. I used Switch Statement with an integer map on an NM for switch cases. I think the problem is that it does not work, at least not when I input day 1. It works as expected when I use int value from 1 to 7. I have tried to find the solution and only so that only the walls are being helped.
Here is my code:
daydays {day 1, day 2, day 3, day 4, day 5, day 6, day 7}; Int Day; Cout & lt; & Lt; "Enter the Day of the Day in Day 1"; CIN & gt; & Gt; day; Switch (day) {issue day1: cout & lt; & Lt; "Sunday"; break; Case 2: Cotton and LT; & Lt; "Monday"; If you want to get input like day1
code>, Day2 etc., why you have declared the input variable as int , it should be the char array. If you like the input 1 , 2 then it's ok okk ... If you want to input string and then compare it with enum values then you have First change it to an integer value.
You can do this,
four days [4]; CIN & gt; & Gt; day; Int d = day [3] -49; Then use it in the switch as you did ..
switch (d) {case days :: day1: cout & lt; & Lt; "Sunday" ; break; Case Day :: Day 2: Cust & lt; & Lt; "Monday"; break;
Comments
Post a Comment