If and else statements with game scores

I am in comp. Sci 1 at my school and I have to write a program that deals with gamer scores and the trophy they get according to expert level. For example Tom is a beginner and gets a gold medal if >=10000 a silver >= 7500 bronze if >= 5000 and no trophy if he score <5000 ! I have do this scoring for Beginner, Immediate and Expert.

Should I set up the beginning like this:
case'b':
case 'B':
if (score >= 10000 )
trophy= gold
if (score >= 7500)
trophy = silver
if (score >= 5000)
trophy= bronze
else = none


Not really sure how to go about solving this problem
Last edited on
try else if

1
2
3
4
5
6
7
8
if (score >= 10000)
  trophy = gold;
else if (score >= 7500)
  trophy = silver;
else if (score >= 5000)
  trophy = bronze;
else
  trophy = none;
case'b':
case 'B':

if (score>=0 && score < 5000)
cout << "No trophy given";
else if ((score >= 5000 ) && (score <= 4499))
cout << "You've earned a Bronze trophy"<<endl;
else if ((score >= 7500) && (
cout << "You've earned a Silver trophy"<<endl ;
else if (score >= 10000)
cout << "You've earned an Gold trophy"<<endl;
else
cout << "Invaid Input"<<endl;



does this seem correct?

or should I do default: cout<<"Invalid Input,"<<endl;
Last edited on
looks good.

if you have no negative scores, you can also drop ''score >= 0'' in the first if.

and maybe you want to have a look at switch case: http://www.cplusplus.com/doc/tutorial/control/
it's a bit easier to read and does the same thing.
There's a problem on this line:
else if ((score >= 5000 ) && (score <= 4499))

You'll never have a score >= 5000 AND <= 4499. The two conditions are exclusive.

I think you are looking for:
else if (( score <= 5000 ) && ( score > 4499 ))
Topic archived. No new replies allowed.