The Multiplication Table | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

The Multiplication Table

I need help. I am working on a C# code coach that I do not understand. Basically, I am an elementary school teacher that explains multiplication to the students. I'll be using the multiples of 3 as my example. Here is the code: using System; using System.Collections.Generic; namespace SoloLearn { class Program { static void Main(string[] args) { int number = Convert.ToInt32(Console.ReadLine()); //your code goes here for (int x = 1; x < 3; x++) { if (number%3==0) { x = number*3; } Console.Write(x*number + "*"); } } } } Here is where I don't get it. On the result, it has to output the multiples of three. Here is where I'm confused: why does it output only 12 and 45? I'm generally confused on that. And if I'm on the right track on my code, what am I missing?

14th Mar 2023, 6:06 PM
Gradi Maxime Kasita Mbatika
1 ответ
+ 2
What your code does right now: 1. you take a number as input 2. you have a loop which is supposed to execute exactly 2 times, with x=1 and x=2 3. if the input is divisible by 3, then you reassign number*3 to x (which is the loop variable) 4. then you print the x*number There are logical errors here. Think what the output should be, given a specific input. Reassigning the loop variable inside the loop, is certainly a bad practice, usually it will reduce the number of times your loop is executed.
14th Mar 2023, 6:19 PM
Tibor Santa
Tibor Santa - avatar