❔ 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
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 consolei understand that, i was just wondering how the script would be written
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 insidelol 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
} } 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
The loop should go from
1
to num
, shouldn't it?
Yours goes from ???
to 12
Angius
REPL Result: Success
Console Output
Compile: 662.123ms | Execution: 58.910ms | React with ❌ to remove this embed.
This is how a
for
loop worksok 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!
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.