Hi everybody

I already see in this forum how to make the program Hailstone Numbers in c++

But i need to make it in c#:confused:

Could any charity soul help me plese...:)

Member Avatar for iamthwee

This couldn't be easier.

Have you drawn a flow chart? If not do so.

Hey, this hailstone numbers thing is pretty cool. Apparently there are some rewards out there for anyone who can solve it (whatever that means.) I embarrased myself the other day when I resserected a very old topic in the C++ C forum from two years ago asking a question about this. (Sorry about that mods!) Anyway, I don't code very well in C++ though I tried to do it. I just coded it in C#. So here it is. Sorry about the delay, I had finals.

using System;
using System.Text;
namespace ConsoleApplication1
{
    class Program
    {
        // Helpful url: [url]http://en.wikipedia.org/wiki/Hailstone_numbers[/url]
        static void Main(string[] args)
        {
            int first;
            System.Console.WriteLine("Enter the integer you would like to run the function on: ");
            first = int.Parse(System.Console.ReadLine());
            while (first != 1)
            {
                System.Console.Write(first + " ");
                first = f(first);
            }
            System.Console.WriteLine(first);
            System.Console.WriteLine("Press enter to continue.");
            ConsoleKeyInfo c = System.Console.ReadKey();
            while (c.Key != ConsoleKey.Enter)
            {
                c = System.Console.ReadKey();
            }
        }
        private static int f(int first)
        {
            if (first % 2 == 0)//test to see if even
            {
                return first /= 2;
            }
            else
            {
                return first = 3 * first + 1;//is odd
            }
        }
    }
}
Member Avatar for iamthwee

Hi Godfear, don't worry about that, we all learn from our mistakes.

However, remember daniweb's homework policy. We don't do ppl's homework, especially if the poster has shown no sign of effort.

thank U it was a BIG BIG help

Your welcome. I hope This wasn't your homework. I don't want to get in trouble for being too helpful.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.