I\'m creating a console app and using a switch
statement to create a simple menu system. User input is in the form of a single character that displays on-screen
'q' || 'Q'
results in bool type result (true) which is promoted to integral type used in switch condition (char) - giving the value 1. If compiler allowed same value (1) to be used in multiple labels, during execution of switch statement menuChoice
would be compared to value of 1 in each case. If menuChoice
had value 1 then code under the first case label would have been executed.
Therefore suggested answers here use character constant (which is of type char) as integral value in each case label.