Statement:
write a program that creates a two dimensional array with 10 rows and 2 columns, The first column should be filled with 10 random numbers between 0 and 100.
* The second column should contain the squared value of the element found in column 1. Using the Show( ) method of the MessageBox class display a table

ok so im gonna have to implement the messagebox.show() line in my program, but i was wondering i already have made an array which will store 10 random values in the first column is there anything i can use which will pull data from their square it and display in the second column leading to a 10x3 array displaying what the question wants?


Thanks as always!

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

namespace twoDimTable
{
    class Program
    {
        static void Main()
        {
            /// '10' denotes rows, '3' denotes columns
            int[,] numTable = new int[10, 3];

            numTable[10, 1] = 1;
            numTable[10, 1] = 100;
            numTable[10, 1] = 45;
            numTable[10, 1] = 22;
            numTable[10, 1] = 88;
            numTable[10, 1] = 33;
            numTable[10, 1] = 5;
            numTable[10, 1] = 12;
            numTable[10, 1] = 98;
            numTable[10, 1] = 39;



            DisplayInstructions(); 

         } // end of main
 
        /// <summary>
        ///  what i need is two make a two dimensional array, store 10 random values 
        ///  in first column, and in second column the numbers from first column squared.
        ///  
        /// method to pull values from first column 
        /// method to draw the array 
        /// </summary>

        public static void DisplayInstructions()

        {
            Console.WriteLine("This program will create a simple two dimensional array with 10 rows and 2 columns.");
            Console.WriteLine("Press any key to continue....");
            Console.ReadKey();

        } // end of DisplayInstructions

        public static DrawRows() 
        {
            
            

        }  // end of DrawRows 

 

        public static DrawTwoDimTable() 
        {

        }  // end of DrawTwoDimTable 
        {}

    } // end of clas s
} // end of namespace
dwarvenassassin commented: Another homework assignment from someone who would ratyher have us do it than do it themselves and risk actually LEARNING something!! -1

You're only supposed to have two columns, right?

You are assigning all of your values to the same index in the 2d array, and I don't think it needs 3 columns.

Putting aside the errors, I think this is the logic you are after:

Random rand = new Random();
for (int i = 0; i < 10; i++)
{
   myArray[i,0]=rand.Next(0, 1000);
   myArray[i,1]=myArray[i,0]*myArray[i,0];
}

What is the point of taking a programming course (which you obviously are) if you are going to rely on the members here to create your code for you? how do you expect to LEARN anything? Do what everyone else does (or should do) before postng todays homework here and RTFM!!

What is the point of taking a programming course (which you obviously are) if you are going to rely on the members here to create your code for you? how do you expect to LEARN anything? Do what everyone else does (or should do) before postng todays homework here and RTFM!!

He's obviously new to programming and has demonstrated that he has put in effort toward his goal (albeit not very much). If his programming teacher is anything like my first one was, he's much better off on these forums than in his classroom. (My teacher's Scottish accent was so thick that it was borderline unbearable).

commented: i had a german teacher who spoke poor english... IN A FRENCH COLLEGE!!! :P +6

I see your point, but it is the "not very much effort" part that makes my teeth itch.
I spent a week trying to code something before I joined daniweb to ask for help. This guy is on here EVERY night with teachers latest homework task.

I see your point, but it is the "not very much effort" part that makes my teeth itch.
I spent a week trying to code something before I joined daniweb to ask for help. This guy is on here EVERY night with teachers latest homework task.

Thanks man, I enjoy your hospitality. Sorry I am not as good programmer as you

So, what I see here are the makings of a console app.
You will need to create a WinForms app (if you are REQUIRED to use a MessageBox to show the contents).
If you are allowed to use a Console App, then it's not a problem (so far).

I recommend encapsulating the generation of the 2d array in one method and then making another method to export that table as either an array of strings or one string.

Example:

private static int[,] GetNumTable()
      {
         // make table and return it here.
      }

      private static string GetDisplayFromNumTable()
      {
         // convert table into a large string and return it here
      }

      static void Main(string[] args)
      {
         /*
          * in a WinForms app, the GetDisplayFromNumTable()
          * will be sent to the MessageBox.Show()
          */
         Console.WriteLine(GetDisplayFromNumTable());
      }

yea i will add a messagebox.show() to it since i need to produce that as well

thanks a lot again

Please help write a coding which will print the numbers stored in arrays(0 to 10) using methods

@nthabiJacq use a for loop, that is all i can say.

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.