+ 2
using System; namespace GoodProgrammerTest { class Program { static void Main(string[] args) { Console.Write("Enter Yes or No"); Console.Write( "Do you programme every day? : ") ; int answer = Console.ReadLine(); if (answer =="Yes") { Console.WriteLine( "You will be a good programmer"); } else { Console.WriteLine( "You will not be a good programmer"); } } } }
3 Antworten
+ 4
The solution is already given. I'll just explain what's going on.
The problem is that you are getting the input which is a string and the you trying to store it in an integer.
So as Aravind fixed the code, change that
"int answer"
with
"string answer"
and the code should work.
0
namespace GoodProgrammerTest
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter Yes or No");
Console.Write(
"Do you programme every day? : ") ;
string answer = Console.ReadLine();
if (answer.ToLower() =="yes")
{
Console.WriteLine(
"You will be a good programmer");
}
else if (answer.ToLower() =="no")
{
Console.WriteLine(
"You will not be a good programmer");
}
else
{
Console.WriteLine(
"Not a valid input");
}
}
}
}
- 1
namespace GoodProgrammerTest
{
class Program
{
static void Main(string[] args)
{
Top: Console.Write("Enter Yes or No");
Console.Write(
"Do you programme every day? : ") ;
string answer = Console.ReadLine();
if (answer.ToLower() =="yes")
{
Console.WriteLine(
"You will be a good programmer");
}
else if (answer.ToLower() =="no")
{
Console.WriteLine(
"You will not be a good programmer");
}
else
{
Console.WriteLine(
"Not a valid input");
goto Top;
}
}
}
}