Jump to content

IF THEN PHP, tough time


dakotaboy99

Recommended Posts

Hello, Im new to the fourm, and just started taking a intro programming class and cant figure this php out, any help?

 

 

Create a PHP program that allows the user to enter in an integer
value that represents the score of a test. Valid integer values are from 0 to 100
inclusive. Display the score (integer value) and the corresponding letter grade. The
grade scale is 10 points.
100 – 90 A
89 – 80 B
79 – 70 C
69 -60 D
Less than 59 F
<?php
$score = 79;
Echo “$score”;
if ($score > 89){
$letter = “A”;
}elseif ($score > 79){
$letter = “ B”;
}
elseif ($score > 69){
$letter = “ C”;
}
elseif ($score > 59){ or <
$letter = “ D”;
>?
This is how our teacher started it off and whanted us to finish

 

Link to comment
Share on other sites

<?php $score = 79; Echo “$score”; IF ($score > 89){ $letter = “A”;}ELSE IF ($score > 79){ $letter = “ B”;}ELSE IF ($score > 69){ $letter = “ C”;}ELSE IF ($score > 59){ $letter = “ D”;>?

 

Not sure, the teacher didnt really teach us much, he basically said to teach yourself this problem, everyone in class didnt understand this

Link to comment
Share on other sites

please use code tags, I can't tell if you are just copy pasting incorrectly or your ending php tag is really broken.

 

also, please tell us the problem is. what value are you expecting for $letter? what is actually happening?

 

You start with score at 79. But you never test if the score could be 79 (or 89, or 69, etc). Make sure you understand your comparison operators.

http://www.w3schools.com/php/php_operators.asp

Link to comment
Share on other sites

Im really lost, the teacher didnt really teach, that is the first part of the code he gave us and thats the question he wanted answered, so im really not sure how to begin or end, this was our 3rd class meeting

 

Create a PHP program that allows the user to enter in an integer
value that represents the score of a test. Valid integer values are from 0 to 100
inclusive. Display the score (integer value) and the corresponding letter grade. The
grade scale is 10 points.....
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...