histogram,simple prob!

mosad2

Newcomer
Joined
Jun 12, 2003
Messages
9
Location
EgYpT
PHP:
using System;
using System.Windows.Forms;

namespace ConsoleApplication4
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Class1
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		/// 
		[STAThread]
		static void Main(string[] args)
		{
			//
			// TODO: Add code to start application here
			//

			int[] n = { 3, 4, 6, 8, 10, 9, 15};
			string output = "" ;
			output += "element\tsubscript\thistogram\t";

			for (int i=0; i < n.Lenght ; i++)
				output += i +"\t" + n[ i ] + "\t";
			for (int j=1; j <  n[i] ; j++)
				output += "*";
			MessageBox.Show ( output,"histogram" , MessageBoxButtons.ok,
				MessageBoxIcon.Information );

				
		}
	}
}
hi guys
would anyone point out why this simple console doesnt compile???
i dont know what's wrong?:(
 
  1. You misspelt "Length".
  2. 'i' is out of scope by the time you come to the second loop. I presume this was meant to be a nested loop. Since only the first statement is inside the first loop, you would need to enclose the two statements in a pair of braces.
  3. C# is case sensitive: MessageBoxButtons has a member 'OK', but no member 'ok'.
    [/list=1]

    Also, your inner loop was counting from 1 to n - 1, so would have printed one too few asterisks.

    Here's an alternative, using a string constructor instead of a nested loop:

    [CS]
    using System;
    using System.Windows.Forms;

    class Histogram
    {
    static void Main()
    {
    int[] n = { 3, 4, 6, 8, 10, 9, 15 };
    string output = "element\tsubscript\thistogram\r\n";

    for (int i = 0; i < n.Length; i++)
    output += i + "\t" + n + "\t" + new string('*', n) + "\r\n";

    MessageBox.Show(output, "histogram",
    MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    }
    [/CS]

    Hope you like that. :cool:
 
Back
Top