0

C# Coding question

Hello, everyone. I'm new to C# and am happy to be learning the language, and happy to be on this site. I'm teaching myself and running into an error with solving a practice problem. Can you tell me why the error is occurring? I can solve for basic output of text and conduct arithmetic operators but I don't understand this problem. Question: Write a C# Sharp program to print the output of multiplication of three numbers which will be entered by the user: Test Data: Input first number to multiply: 2 Input second number to multiply: 3 Input third number to multiply: 6 Expected Output: 2X3X6=36 Here is my code below to solve for it. I would really appreciate some help. Thank you. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void sayHi() { Console.WriteLine("Hello"); Console.WriteLine(-1+4*6); Console.WriteLine((35+5)%7); Console.WriteLine(14+-4*6/11); Console.WriteLine(2+15/6*1-7%2); int 2, 3, 6 Console.Write("2"); num2=Convert.ToInt32(Console.ReadLine()); Console.Write("3"); num3=Convert.ToInt32(Console.ReadLine()); Console.Write("6"); num6 = Convert.ToInt32(Console.ReadLine()); int result = 2 * 3 * 6; Console.WriteLine("Output: {0} x {1} x {2} = {3}", num1, num2, num3, result); } static void Main(string[] args) { sayHi();

20th Jul 2018, 12:36 PM
Alex
Alex - avatar
3 Respostas
0
i can't really make out much of what's going on in your code, but here's an elegant way to do what you need to do, inputting the numbers in seperate lines gives the desired result, ask me any needed questions. https://code.sololearn.com/cypa3QmTclGX/?ref=app
20th Jul 2018, 12:55 PM
hinanawi
hinanawi - avatar
0
Hi, looking at your code I don't understand the line which says: int 2,3,4 Is this an attempt of declaration? You can't do that, you should change that line by this one: int num1, num2, num3; *DON'T FORGET THE SEMICOLON* Because you are calling this three variables without declaring it. All variables that you want to use MUST be declared before, I saw that you are using num6 variable without declaring it. So... Change lines where you get the user input, assign it to variables num1 num2 and num3, not num2 num3 and num6. Also you should change the line that says: int result = 2*3*6; What if an user input is not 2, 3 and 6? Maybe I want to put 3,7 and 9, but with this line, the result is always 2*3*6, so change it : int result = num1 * num2 * num3; Try to do this and your code will work, if you still can't solve it I will share your code with the solution Hope it helps you!
20th Jul 2018, 1:26 PM
Guillem Padilla
Guillem Padilla - avatar
0
What answer
12th May 2022, 5:53 AM
Dhivahar 2008