I can write a basic switch statement no problem. But I am trying a more complex one that evaluates a players game score in 4 'tiers' out of 100, but it is not working so...
Heres the code first.
//Using switch statement to add more than 2 responses to player score
#include <iostream>
using namespace std;
int main ()
{
int score;
cout << "What was your score?";
cin >> score;
switch (score)
{
case (score <=25):
cout << "\nOuch, less than 25...!";
break;
case (score <=50):
cout << "\nYou score aint great mate..";
break;
case (score <=75):
cout << "\nYour pretty good, wel done man!";
break;
case (score <=100):
cout << "\nYou got to the top!!!";
break;
default:
cout << "\nYou cant score higher than 100!!! Cheater!!!!";
}
cin.ignore();
cin.get();
return 0;
}
My Complie log hits the first case statement and reports a case label does not reduce to an integer constant.
Ok, now, question one;
1) can I put a test into the value of each case?? If not, thats the simple answer, but if thats the case, what function would you use to achieve the same idea. If you can do the testing on to two..
2) my only other thought of why this isnt working is that the value is not realy an integer, as I believe that switch statements only work with integers, so it wouldnt work??
If its not one of the above two, can someone give me some help as to why its not working??? Thanks folks.
As an aside, I'm currently working with Dev C++ and using the book Beginning C++ Game Programming by Micheal Dawson, but I'm only just getting into the 3rd Chapter on Arrays....
Cheers
Kal











