I am attempting to create a C# program with two classes that will make a decision based on the user's input to output a response (ex. the user says rock and the computer says paper) that makes the user always lose. I currently have errors saying
"Cannot implicitly convert type 'int' into type 'string'" on lines with all of the cases ("case1:", "case2:", "case3:").
Yet I have defined the "nameClassif" as a string just above. I also have a warning: Warning CS0649: Field 'Player.classif' is never assigned to, and will always have its default value null
using System;
using static System.Console;
namespace Tes
{
class PlayerApp
{
public static void Main()
{
Player player1 = new Player();
player1.PlayerChoice = InputValue();
player1.Classif = InputValue();
Clear();
Write(player1);
Write("\n\n\n\n");
ReadKey();
}
public static string InputValue()
{
Write("Please enter rock, paper, or scissors:\t");
return ReadLine();
}
}
class Player
{
private string classif;
// constructors
public Player()
{ }
public Player(string pC)
{
PlayerChoice = pC;
}
// properties
public string PlayerChoice { get; set; }
public string Classif { get; set; }
public double SetFine()
{
if (classif == "rock")
{
WriteLine("The computer chose paper. You lose.");
}
else if (classif == "paper")
{
WriteLine("The computer chose scissors. You lose.");
}
else if (classif == "scissors")
{
WriteLine("The computer chose rock. You lose.");
}
return SetFine();
}
public string ReturnNameOfClassification()
{
string nameClassif;
switch (classif)
{
case 1: nameClassif = "rock"; break;
case 2: nameClassif = "paper"; break;
case 3: nameClassif = "scissors"; break;
default:
WriteLine("Invalid selection..." +
" I assume you chose rock... :");
nameClassif = "rock - ???"; break;
}
return nameClassif;
}
public override string ToString()
{
return "\n\n\n\t\tRock-Paper-Scissors" +
"\nThe computer chose\t" + PlayerChoice;
}
}
}
string a = 5;