In the application I'm writing, one of the methods allows for the numbers the user entered to be turned into letters. For example, the user will be entering grades (as doubles) and the program will decide (when the criteria is met) to return the letter associated with the number. Initially, I had it written like this:
public void GetGrade(double scores) Console.Write("Score of {0} earns: ", score);
if (score >= 95.0)
Console.WriteLine("A+");
else if (score >= 90.0)
Console.WriteLine("A");
else if (score >= 85.0)
Console.WriteLine("B+");
else if (score >= 80.0)
Console.WriteLine("B");
else if (score >= 75.0)
Console.WriteLine("C+");
else if (score >= 70.0)
Console.WriteLine("C");
else if (score >= 65.0)
Console.WriteLine("D+");
else if (score >= 60.0)
Console.WriteLine("D");
else
Console.WriteLine("F");
But it needs to be written with a RETURN in mind. So, I think it should be public string GetGrade(double scores) And since it's in an array I would need:
foreach(double score in scoress) { THE CODE I POSTED ABOVE }
Except I'd change all the console.writeline's to return. However, when I do that I get a syntax error telling me: "A local variable named score cannot be declared in this scope because it would give a different meaning to 'score', which is already used in parent or current scope to denote something else."
So, I gather that I cannot use score because the header already contains score. How do I go about getting this to work how I want it?