samedi 28 mars 2020

Forced to use switch statement to test for conditions

My professor gave us a seemingly straightforward homework assignment, but with one frustrating twist: we cannot use if/else if/else statements and we must use a switch statement instead. The homework problem is as follows:

Write a program that will read in the number of credit hours completed by a student at a university. Based on the number of credit hours completed, classify the student as a freshman, sophomore, junior, or senior (freshman: hours < 32, sophomore: 32 <= hours < 64, junior: 64<= hours < 96, senior: 96 <= hours). Don't use if/else if/else statements. You must use switch statements.

I know how to write this program using if statements but I have no idea how to write this with a switch statement. From what I've read, switch statements aren't supposed to be used in this way, yet here I am... Please do not answer telling me to use if statements, because I can't!

Aucun commentaire:

Enregistrer un commentaire