C
C#5w ago
jota

help with project for school, the program keeps looping and doesn't stop adding "*"

Console.WriteLine("how many lines do you need?");
int l;
l = int.Parse(Console.ReadLine());
Console.WriteLine("how many columns do you need?");
int c;
c = int.Parse(Console.ReadLine());
int i = 0;
while (i < l)
{
Console.WriteLine("*");
i = i + 1;
while (i < c)
Console.WriteLine("*");
i = i + 1;
}
Console.WriteLine("how many lines do you need?");
int l;
l = int.Parse(Console.ReadLine());
Console.WriteLine("how many columns do you need?");
int c;
c = int.Parse(Console.ReadLine());
int i = 0;
while (i < l)
{
Console.WriteLine("*");
i = i + 1;
while (i < c)
Console.WriteLine("*");
i = i + 1;
}
4 Replies
jcotton42
jcotton425w ago
while (i < c)
Console.WriteLine("*");
i = i + 1;
while (i < c)
Console.WriteLine("*");
i = i + 1;
the while loop here only applies to the console.writeline one of the hazards of not indenting your code properly properly indented, your code is
Console.WriteLine("how many lines do you need?");
int l;
l = int.Parse(Console.ReadLine());
Console.WriteLine("how many columns do you need?");
int c;
c = int.Parse(Console.ReadLine());
int i = 0;
while (i < l)
{
Console.WriteLine("*");
i = i + 1;
while (i < c)
Console.WriteLine("*");
i = i + 1;
}
Console.WriteLine("how many lines do you need?");
int l;
l = int.Parse(Console.ReadLine());
Console.WriteLine("how many columns do you need?");
int c;
c = int.Parse(Console.ReadLine());
int i = 0;
while (i < l)
{
Console.WriteLine("*");
i = i + 1;
while (i < c)
Console.WriteLine("*");
i = i + 1;
}
jota
jota5w ago
thanks, but I'm not understaning it I'm new to coding and recently got into it through school the code I see there looks like what I just wrote out, but with the colors properly assigned to each word (thank you btw)
jcotton42
jcotton425w ago
without braces, a loop only applies to the next line what you wanted was
while (i < c)
{
Console.WriteLine("*");
i = i + 1;
}
while (i < c)
{
Console.WriteLine("*");
i = i + 1;
}
jota
jota5w ago
OH, okay thanks
Want results from more Discord servers?
Add your server