Beginner - chapter 6 - test 2

Hello,
I’m trying to solve the test about creating a rhombus.
When I run my code the ouput seems correct but I get a error :
“Errors from testing your code: The code gave an unexpected output for input: 21”.
When the input is 21 the rhombus looks good.

Here is my code :

using System;

namespace Exam

{

class Rhombus

{

    static void Main()

    {

        var size = int.Parse(Console.ReadLine());                      

        int nbrEspaces = size / 2;

        int nbrDieses = 1;

        int i = 0;

        while (i < size)

        {

            while (nbrDieses < size + 1)

            {

                for (int j = 0; j < nbrEspaces; j++)

                {

                    Console.Write(" ");

                }

                for (int k = 0; k < nbrDieses; k++)

                {

                    Console.Write("#");

                }

                Console.WriteLine();

                i++;

                nbrDieses += 2;

                nbrEspaces--;

            }

            nbrDieses = size - 2;

            while (nbrDieses >= 1 )

            {

                for (int j = 0; j < (size - nbrDieses ) /2 ; j++)

                {

                    Console.Write(" ");

                }

                for ( int k = nbrDieses; k > 0; k--)

                {

                    Console.Write("#");

                }

                Console.WriteLine();

                i++;

                nbrEspaces++;

                nbrDieses -= 2;

               

            }

        }  

    }  

}

}

Can anyone give me a clue ?
Thanks

Hi @nath40360, welcome to Codeasy!

You did a great job on this task, it is almost completely correct. The only detail from the task description that is not present in your solution is that the area to the right from the rhombus should also be filled with spaces (same as you did to the area to the left)

Hi @Dmytro_Shervarly
Thank you for your answer.
I will work on that point.

1 Like