0

I am currently working my way through a Wrox C# book. However, following one of the tutorials that displays a Mandelbrot set, I am able to execute my program without error, however nothing is being displayed in the console. I am putting this down to an incorrect use of the switch I am using. Could anyone point me in the right direction?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ch03Ex06
{
    class Program
    {
        static void Main(string[] args)
        {
            double realCoord, imagCoord;
            double realTemp, imagTemp, realTemp2, arg;
            int iterations;
            for (imagCoord = 1.2; imagCoord >= -1.2; imagCoord -= 0.05)
            {
                for (realCoord = -0.6; realCoord <= 1.77; realCoord += 0.03)
                {
                    iterations = 0;
                    realTemp = realCoord;
                    imagTemp = imagCoord;
                    arg = (realCoord * realCoord) + (imagCoord * imagCoord);
                    while ((arg < 4) && (iterations < 40));
                    {
                        realTemp2 = (realTemp * realTemp) - (imagTemp * imagTemp) - realCoord;
                        imagTemp = (2 * realTemp * realTemp) - imagCoord;
                        arg = (realTemp * realTemp) + (imagTemp * imagTemp);
                        iterations += 1;
                    }
                    switch (iterations % 4)
                    {
                        case 0:
                            Console.Write(".");
                            break;
                        case 1:
                            Console.Write("o");
                            break;
                        case 2:
                            Console.Write("O");
                            break;
                        case 3:
                            Console.Write("@");
                            break;
                    }
                }
                Console.Write("\n");
            }
            Console.ReadKey();
        }
    }
}
IronAces
  • 1,857
  • 1
  • 27
  • 36

3 Answers3

10

i guess the program runs forever, because of this line

         while ((arg < 4) && (iterations < 40));

the ; at the end closes this while loop without entering the next block

user287107
  • 9,286
  • 1
  • 31
  • 47
1

You have a typo:

while ((arg < 4) && (iterations < 40));

; must be removed

quantdev
  • 23,517
  • 5
  • 55
  • 88
1

This is your problem, remove the semicolon

while ((arg < 4) && (iterations < 40));
Syed Farjad Zia Zaidi
  • 3,302
  • 4
  • 27
  • 50