The problem
Write a console-based application that displays a
multiplication table of the product of every integer from
1 through 10 multiplied by every integer from 1 through
10.
What I have done so far
double firstNumberBottom = 1;
double increment;
double something;
const double firstNumberTop = 1;
const double maxNumberTop = 10;
const double numberIncrement = 1;
const double maxNumberBot = 10;
const double maxNumberincrement = 1;
Console.WriteLine(" Number");
for (increment = firstNumberTop; increment <= maxNumberTop; increment += numberIncrement);
Console.WriteLine("{0, 8}", increment.ToString("F"));
Console.WriteLine();
Console.WriteLine
("-------------------------------------------------");
increment = firstNumberTop;
while (firstNumberTop <= maxNumberBot)
{
Console.WriteLine("{0, 8}", firstNumberTop.ToString("C"));
while (increment <= maxNumberTop)
{
something = firstNumberTop * increment;
Console.Write("{0, 8}", something.ToString("F"));
increment += 1;
}
firstNumberBottom += maxNumberincrement;
increment = firstNumberBottom;
Console.WriteLine();
}
It doesnt work.....
It should look something like that I am guessing
1 2 3 4 5 6 7 8 9 10
1
2
3
4
5
6
7
8
9
10
Loading
VulpesPosted Jan 5, 2012, 6:40 AM
The following should give a reasonably tidy display though you first need to change the label's Font property in the Properties Box to a non-proportional font such as Consolas - otherwise the table will be all over the place:
VulpesPosted Jan 5, 2012, 9:55 AM
Anyway, he has both versions now :)
Posted Jan 5, 2012, 9:51 AM
VulpesPosted Jan 5, 2012, 9:43 AM
In my windows forms version, I added row headings as well and 'dividers' between the headings and the actual numbers.
Posted Jan 5, 2012, 8:01 AM
using System;
namespace Loops_problem_please_help
{
class Program
{
static void Main(string[] args)
{
for (int x = 1; x <= 10; ++x)
{
Console.Write("{0, 5}", x);
}
Console.WriteLine("\n");
for (int x = 2; x <= 10; ++x)
{
for (int y = 1; y <= 10; ++y)
{
Console.Write("{0, 5}", x * y);
}
Console.WriteLine("\n");
}
Console.ReadKey();
}
}
}
Prime bPosted Jan 4, 2012, 10:58 PM
\
private void button1_Click(object sender, EventArgs e)
{
for (int x = 1; x <= 10; ++x)
{
label1.Text = String.Format("{0, 5}", x);
}
label1.Text = String.Format("\n");
for (int x = 1; x <= 10; ++x)
{
for (int y = 1; y <= 10; ++y)
{
label1.Text = String.Format("{0, 5}", x * y);
}
label1.Text = String.Format("\n");
Prime bPosted Jan 4, 2012, 10:52 PM
Prime bPosted Jan 4, 2012, 10:39 PM
Posted Jan 4, 2012, 9:03 PM
In this program I started with small numbers that means three numbers then it was easy to identify the errors and correct it, then extent it to 10 numbers this was the way I did it.
In my view in this program all numbers are integers. I don't how double comes to your program.
using System;
namespace Loops_problem_please_help
{
class Program
{
static void Main(string[] args)
{
for (int x = 1; x <= 10; ++x)
{
Console.Write("{0, 5}", x);
}
Console.WriteLine("\n");
for (int x = 1; x <= 10; ++x)
{
for (int y = 1; y <= 10; ++y)
{
Console.Write("{0, 5}", x * y);
}
Console.WriteLine("\n");
}
Console.ReadKey();
}
}
}