I'm trying to create a leveling system for a text based RPG that I'm making. The problem I'm running into is that it seems ranges won't work with switch cases. Here is what I have:
int exp = 0, level = 1, hp = 10, hpmax = 10;
if (exp >= 262144) exp = 262144;
switch (exp)
{
case (4 - 15):
level = 2;
hp = 12;
hpmax = 12;
break;
case (16 - 63):
level = 3;
hp = 14;
hpmax = 14;
break;
case (64 - 255):
level = 4;
hp = 16;
hpmax = 16;
break;
case (256 - 1023):
level = 5;
hp = 18;
hpmax = 18;
break;
case (1024 - 4095):
level = 6;
hp = 20;
hpmax = 20;
break;
case (4096 - 16383):
level = 7;
hp = 20;
hpmax = 20;
break;
case (16384 - 65535):
level = 8;
hp = 22;
hpmax = 22;
break;
case (65536 - 262143):
level = 9;
hp = 24;
hpmax = 24;
break;
case (262144 - 999999999):
level = 10;
hp = 26;
hpmax = 26;
break;
Yes, I realize this doesn't do what I want it to do. I'm not quite satisfied with the alternatives that I've found. I'm looking for the simplest solution. I'm new to programming so any help would be appreciated.