C# coding error- Learning

josh.gillespie1998

Prominent
Aug 30, 2017
10
0
560
I have highlighted the error. I can't see the issue with it. Please help! :)



___________________code____________________________

using System.Text;
using System.Threading.Tasks;

namespace FirstConsoleProject
{
class Program
{
static void Main(string[] args) //this is a method called Main. It is called when the program starts.
{
Start:

Console.WriteLine("Welcome to the quiz! This test has a series of questions to be answered.");
Console.WriteLine("\rGet any wrong, you have to start again.");
Console.WriteLine("\rPress enter to begin!");
Console.ReadKey();


//Question 1
Console.WriteLine("What is 10 divided by 2?"); //This is text that can be seen.
Console.ReadKey(); //This lets the player type into the console.

int answer = Convert.ToInt32(Console.ReadLine());
if (answer == 5) //Checks if the answer is correct
{
Console.WriteLine("You have answered 5, This is correct");
}

else if (answer != 5) // if it is not correct it will output this message
{
Console.WriteLine("You have answered " + answer + ", this is incorrect. Try again!");
Console.ReadKey();

goto Start; //This will send the player back to the start.
}

}

}







 

josh.gillespie1998

Prominent
Aug 30, 2017
10
0
560
using System;
namespace FirstConsoleProject

{

class MainClass

{

public static void Main(string[] args) // this is a method called "Main". It is called when the program starts.

{

int num01 = 16;

int num02 = 4;
Console.WriteLine("What is " + num01 + " times " + num02 + "?");
int answer = Convert.ToInt32(Console.ReadLine());
if (answer == num01 * num02)
{

Console.WriteLine("Well done! Your answer is correct.");

}
else
{

Console.WriteLine("Are you even trying?");

}
Console.ReadKey();

}

}

}
 
1. One of the ways to process console input where numbers-only are expected is to enclose string-to-number conversion in "try / catch " block.
2. Using "goto" for simple loop is not the proper way to write software in 2018.
3. The prompt to the user suggests that if it provides "correct" answer, he/she won't have to start over, which is not the case.