Reputation: 29
This the code that I have; The items that I have is:
string gradepct = null;
int testScore = 100;
if (testScore <= 60) { gradepct = "F";}
else if (testScore < 69) {gradepct = "D";}
else if (testScore < 79) {gradepct = "C";}
else if (testScore < 89) {gradepct = "B";
} else {gradepct = "A";}
Console.WriteLine ("You have recived the grade of gradepct!");
Console.WriteLine ("Please enter a correct grade")
Upvotes: 0
Views: 90
Reputation: 15806
You can set the testScore
as a parameter of the method. And every time the method received a grade, you will get the gradepct in test method.
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
Console.WriteLine("Please enter a correct grade");
test(69);
test(71);
test(55);
}
public void test(int testScore) {
string gradepct = "";
if (testScore <= 60) { gradepct = "F"; }
else if (testScore < 69) { gradepct = "D"; }
else if (testScore < 79) { gradepct = "C"; }
else if (testScore < 89)
{
gradepct = "B";
}
else { gradepct = "A"; }
Console.WriteLine("You have recived the grade of gradepct:" + gradepct );
}
}
Upvotes: 1
Reputation: 12181
Look at this line:
if (testScore >= 0 &&int gradepct = 110;testScore <=100)
You can't put int gradepct = 110;
in the middle of the condition for your if
statement like this. Also, you should use brackets after the if
statement. Rewrite it to this:
int gradepct = 110;
if (testScore >= 0 && testScore <=100)
{
....
}
That actually won't work either, though - you made gradepct
of type int
, but you're trying to assign a string
to it, e.g.:
gradepct = "C";
Also, it's a little unclear why you're assigning 110
to it in the first place - it'll always be set in the course of your if
statements, so you really don't need to set it to anything in particular.
You should do the following instead:
string gradepct = null;
if (testScore >= 0 && testScore <=100)
{
...
}
Also, please check to see whether you did, in fact, declare testScore
anywhere. (If you did, you likely have another compile error in the program).
Upvotes: 1