C++, I am trying to understand how I can replace 1 for monday, 2 for tuesday 3 for wednesday ect using the switch statement "if"
@AravindG can you help me bro? :/
@phi @robtobey
@Hero
are you not allowed to use a "switch" statement example http://www.cplusplus.com/forum/beginner/20212/
I googled that too phi, but "if" statement is also a switch statement, and that's what I need to use for this one
I have to use*
use strcmp(str,"monday") or compare (google it) if (strcmp(str,"monday")==0) xx= 2; else if (strcmp(str,tuesday")==0) xx= 3; else...
To give you an example of what I need exactly take a look at this http://screencast.com/t/ApfdaNkpRh
That says all you need are 2 numbers....the user types in 0 for Monday.. Are you doing something different ?
If the user typed in 0 for the day, and 0 days later, the answer is 0 to printout "Monday is 0 days away" I would use an array indexed by the day's number. DayNames[0] would return "Monday" for example
if you must use an if, it would look like this if (num==0) str= "Monday"; else if (num==1) str= "Tuesday"; else ...
I agree with phi, the easiest way would be an array so you would just return the item at index (start + days_forward) modulo 7. As for using the 'switch' statement (if..else if..else or switch..case) you would calculate num = (start + days_forward) modulo 7 and then do as he says if (num == 0) ...
Join our real-time social learning platform and learn together with your friends!