C
C#9mo ago
Block

❔ Trying to figure out how to write a simple script

I'm fairly new to c# and I'm trying to figure out how to write this question in a for loop. it goes -6. Define a method named DisplayMultiplicationTable that takes an integer parameter. a. The method loops through all the values between 1 and 12 (inclusive) and display the multiplication with the parameter value in a statement like this 5 x 3 = 15. b. Call the method in the Start() with a value of 3. The output should look like this: 3 x 1 = 3 3 x 2 = 6 3 x 3 = 9 3 x 4 = 12 etc. Help would be very much appreciated!!!
9 Replies
Angius
Angius9mo ago
Well, a for loop will go from whatever number you want to whatever other number you want Then multiply it by the given parameter And print to console
Block
Block9mo ago
i understand that, i was just wondering how the script would be written
Angius
Angius9mo ago
I'm not gonna do your homework for you, if that's what you're hoping for It would be a method With a parameter And a for loop inside
Block
Block9mo ago
lol ik how to write the method and the parameter. Im just having trouble getting the for loop to work properly. void DisplayMultiplicationTable(int num) { int i = 0; for(i = num; i <= 12; i++) { int sum = i * num; Debug.Log(num+ "x" + i + " = " + sum);

} } I have it written like this, i just want the second number to start at 1 and not 3, thats mostly what im struggling with and the parameter is set to 3
Angius
Angius9mo ago
The loop should go from 1 to num, shouldn't it? Yours goes from ??? to 12
MODiX
MODiX9mo ago
Angius
REPL Result: Success
for (int i = 0; i <= 5; i++)
{
Console.WriteLine($"Number {i}");
}
for (int i = 0; i <= 5; i++)
{
Console.WriteLine($"Number {i}");
}
Console Output
Number 0
Number 1
Number 2
Number 3
Number 4
Number 5
Number 0
Number 1
Number 2
Number 3
Number 4
Number 5
Compile: 662.123ms | Execution: 58.910ms | React with ❌ to remove this embed.
Angius
Angius9mo ago
This is how a for loop works
Block
Block9mo ago
ok i figured out what i was doing wrong LMAO i fixed it and got it working lol i feel dumb, but thank you for the help!
Accord
Accord9mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.