How could I add my logic?

Ant6729Gr

New member
Hello
I need to cycle my attempts untill I dont want to insert data

Here my code
Could you help me?

Test:
``````using System;

namespace blabla
{
public delegate int BinaryOp(int x, int y);
public class SimpleMath
{
public static int Add(int x, int y)
{ return x + y; }

}

class Program
{

static void Main(string[] args)
{
BinaryOp b = new BinaryOp(SimpleMath.Add);
int userresult;
int pcresult;

Console.WriteLine("Insert first number");
int x = (Convert.ToInt16(Console.ReadLine()));

Console.WriteLine("Insert second number");
int y = (Convert.ToInt16(Console.ReadLine()));

//MyMethod();

Console.WriteLine("Insert sum of x and y");

pcresult = b(x, y);

if (userresult != pcresult)

{
Console.WriteLine("Something wrong with your calculations, man..." + "\n" + "Would you like to continue...? (y/n) : ");

{
case "y":

//Console.WriteLine("Insert sum of x and y");

break;

case "n":
Console.WriteLine("If I were you, I’d better practice over....You never know...");
break;

default:
break;
}
}

else
{
Console.WriteLine("Right");
}
}
}
}``````

You would a do-while loop to surround most of your code so that it loops back again to the beginning and get the "cycle" that you are looking for.

Within that loop, you'll likely also need another do-while loop to handle the case when the user if they want to try again when they get the answer wrong.

As an aside, on line 40, you don't need to convert the return value of `Console.ReadLine()` to a string because it already returns a string.

Replies
8
Views
450
Replies
7
Views
2K
Replies
6
Views
1K
Replies
13
Views
1K
Replies
8
Views
1K