+ 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"); } } } }

6th Aug 2016, 2:04 AM
Wilson Bol
Wilson Bol - avatar
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.
6th Aug 2016, 7:23 AM
Alireza M
Alireza M - avatar
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"); } } } }
6th Aug 2016, 5:26 AM
Aravind R S
Aravind R S - avatar
- 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; } } } }
6th Aug 2016, 1:08 PM
Samuel Neo
Samuel Neo - avatar