user3380700
user3380700

Reputation: 1

How to print Multiplication table by taking values from user using two do-while loops

I need help in this code it gives an error. Please give appropriate answer to this question.. where I am just stuck and on which part of the code?

Using Do-while Loop:

Console.writeLine("Multiplication table");

int a;
Console.writeLine("Enter the Multiplication table no");
a = Convert.ToInt32("Console.ReadLine());

int b;
Console.writeLine("Enter the Limit");
b = Convert.ToInt32("Console.ReadLine());

int c;
do
{
     a++;
     int d = 1;
do
{
    Console.writeline(c+"*"+d+"="+(c*d));
    b++;
  }

while(c<=3)

Upvotes: 0

Views: 2545

Answers (3)

Ben
Ben

Reputation: 2523

As people have stated before, there are a few issues with this question for us to be able to provide a solid answer; incomplete code and not knowing exactly what the error you are receiving for a start.

However, from what I can piece together (making a few assumptions of course)

  1. The big one is the non-initialisation of int c;. c must equal something before you call it. eg. int c = 0 will remove that problem.

  2. I'm assuming that your do {} while () loops are fully enclosed? i.e.

    do 
    {
        do { something }
        while(something is true)
    }
    while (something else is true)
    

However, this seems a bit obsolete.

  1. The function

    Console.WriteLine(c+"*"+d+"="+(c*d));
    b++;
    

doesn't really make sense to me. Should you be using b instead of c? If not, then does c = b?

Upvotes: 3

GetSome
GetSome

Reputation: 1

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim counterR As Integer = 1
    Dim counterC As Integer = 1
    Do While counterR <= 10
        Do While counterC <= 10
            TextBox1.Text += (counterC * counterR).ToString + " "
            'TextBox1.Text += counter.ToString + vbCrlf
            counterC += 1
        Loop
        TextBox1.Text += vbCrLf
        counterR += 1
        counterC = 1
    Loop

End Sub

End Class

Upvotes: -2

Mike
Mike

Reputation: 73

I can't see the second while statement so I have to guess you made it just after the first one, if not then you would get an Compiler Error.

You just delarated c but never set it to any value so c<=3 is always true and you end up in an endless loop.

Upvotes: 0

Related Questions