Jump to content
  • Advertisement
Sign in to follow this  
Afr0m@n

Unity [.net] Is this program working correctly?

This topic is 4387 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If anyone spots any errors in this program, can they please let me know ASAP? I know there aren't any syntactical errors, but if there are any runtime errors, it is critical for me to know ASAP. I wouldn't normally make a post like this, but the reason I'm doing it now is because the program is causing the computer to make an awful lot of noise due to some ASCII characters I'm printing out, and as such I can't really use the computer now, so I'd really like to turn the program off if it isn't going to work correctly anyhow. I don't need to know the reason it's making sounds, as I already know that, I just need to know if the program is working correctly. Thanks! Here's the source:
using System;
using System.Collections.Generic;
using System.Text;

namespace Codemonkey_test
{
    class Program
    {
        static void Main(string[] args)
        {
            GenerateFunction();
        }

        static void GenerateFunction()
        {
            char[] ChrArray = new char[30];
            int[] ASCII = new int[30];
            bool Exit = false;

            Random Rnd = new Random();

            while (!Exit)
            {
            Start:
                for (int i = 0; i < ChrArray.Length; i++)
                {
                    ASCII = Rnd.Next(1, 255);
                    ChrArray = (char)ASCII;
                }

                string Str = new String(ChrArray);
                Console.WriteLine(Str);

                if (Str.Equals("Potato getPotato(){return potato;}", StringComparison.CurrentCultureIgnoreCase))
                    Exit = true;
                else
                    goto Start;
            }
        }
    }
}

Please look at my last post in this thread for a reference as to why I created this thread and the program.

Share this post


Link to post
Share on other sites
Advertisement
First of all, gotos are the root of all evil and you definately do not need it in what you're doing right now. If you remove "Start:" and the else statement, then it should be fine.

The unfortunate thing are the chances of ever getting "Potato getPotato(){return potato;}" from a random generation of characters. The loop will most likely never break, because it'll almost never randomly generate that string.

Share this post


Link to post
Share on other sites
Thanks! :)

And yes, I'm beginning to think you're right about the last part. As of now the program's been running for over 15 hours and still hasn't produced any result. :\

Share this post


Link to post
Share on other sites
if you change your random range to 32,255 that way you won't be trying to print control characters, of which BEEP is sub 32 iirc.

Share this post


Link to post
Share on other sites
Quote:
Original post by Niksan
if you change your random range to 32,255 that way you won't be trying to print control characters, of which BEEP is sub 32 iirc.
If doing that, you might as well limit to ASCII and use 32, 127.
Quote:
Original post by Rob Loach
First of all, gotos are the root of all evil...
Complete and utter nonsense. That said, I agree that there is no need for a goto there.

I'd prefer to do it like this:

for ( ; ;) { // while (true) is also a possibility

// Build up string...

if (Str.Equals("Potato getPotato(){return potato;}", StringComparison.CurrentCultureIgnoreCase)) {
break;
}

}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!