I am having trouble with this project. The project is to use user input to take scores. Using a loop that allows the user to input as many scores that they want. I am having a difficult time passing a variable to my ConvertToInt method. I am wanting to pass the variable, with the value, score to the ConvertToInt method. In the ConvertToInt method I have to convert the string to an int. What I have coded now will run but after entering a score the System.FormatException is thrown. I am new to C# and do not quite understand what is wrong.
using System;
namespace MethodsAndUnitTestsMethodTestsCampbell
{
class Program
{
private static string GetUserInput(string scores)
{
Console.WriteLine("Enter score: ");
string score = Console.ReadLine();
score = scores;
return score;
}
private static int ConvertToInt(string scores)
{
return Convert.ToInt32(scores);
}
static void Main(string[] args)
{
string scores = "{C} ";
GetUserInput(scores);
ConvertToInt(scores);
}
}
}
GetUserInputmethod? Right now, you are passing the string '{C} ' to yourConvertToIntmethod, and that definitely can't be converted to an int.