samedi 5 juin 2021

How do I return a value from an if statement?

I am very new to not only C# but programming as a whole, and I understand that this is a very basic question, but I just dont know how to return a value from an if statement. This is my code:

 static void Main(string[] args)
    {
        int couscous = RandomNumber(1);
        Random rnd = new Random();
        while (couscous > 1)
        {

            
            int remainder = couscous % 3;
            if (remainder == 0)
            {
                Console.WriteLine(couscous / 3);
                int step2 = couscous / 3;
               // I want to return couscous / 3 to the beginning of the while statement so it repeats all the code but with step2 instead of couscous.
                
            }
            else if (remainder != 0)
            {
                Console.WriteLine(couscous + 1);
                
            }



        }




    }
    static int RandomNumber(int i) 
    {
        Random rnd = new Random();
        i = rnd.Next(1, 1000);
        int input = i;
        return input;
        

Aucun commentaire:

Enregistrer un commentaire