C
C#16mo ago
DimOn4ik

❔ Please help me write code

///
35 Replies
DimOn4ik
DimOn4ikOP16mo ago
I don't understand what is wrong here
Pobiega
Pobiega16mo ago
please dont post screenshots of code. $code
MODiX
MODiX16mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
DimOn4ik
DimOn4ikOP16mo ago
using System; using System.ComponentModel.Design; using System.Net.Security; namespace Program { class Program { static void Main() { System.Console.Write("Введите число:" ); short x = Convert.ToInt16(Console.ReadLine());
System.Console.Write("Умножить или разделить или прибавить или уменьшить?:"); string bebra = Console.ReadLine() ; if ( bebra == "1") { System.Console.Write("Выбери число:"); short d = Convert.ToInt16(Console.ReadLine()); Console.Write("Ответ:" + (x * d));





} if ( bebra == "2") { System.Console.Write("Выберите число.:"); short e = Convert.ToInt16(Console.ReadLine()); Console.Write("Ответ:" + (x / e)); if ( bebra == "3") { System.Console.Write("Напиши число.:"); int f = Convert.ToInt32(Console.ReadLine()); Console.Write("Ответ:" + (x + f)); if ( bebra =="4") { System.Console.Write("Число дай:"); int g = Convert.ToInt32(Console.ReadLine()); Console.Write("Ответ:", x - g); } } }
} }

}
Pobiega
Pobiega16mo ago
Read the instructions again You missed the important part
DimOn4ik
DimOn4ikOP16mo ago
That's what I wrote, because I don't understand what's wrong here
Pobiega
Pobiega16mo ago
$codegif
DimOn4ik
DimOn4ikOP16mo ago
I don't spell it that way
Pobiega
Pobiega16mo ago
Console.Write("Введите число:");
short x = Convert.ToInt16(Console.ReadLine());

Console.Write("Умножить или разделить или прибавить или уменьшить?:");
string bebra = Console.ReadLine();
if (bebra == "1")
{
Console.Write("Выбери число:");
short d = Convert.ToInt16(Console.ReadLine());
Console.Write("Ответ:" + (x * d));
}

if (bebra == "2")
{
Console.Write("Выберите число.:");
short e = Convert.ToInt16(Console.ReadLine());
Console.Write("Ответ:" + (x / e));
if (bebra == "3")
{
System.Console.Write("Напиши число.:");
int f = Convert.ToInt32(Console.ReadLine());
Console.Write("Ответ:" + (x + f));
if (bebra == "4")
{
System.Console.Write("Число дай:");
int g = Convert.ToInt32(Console.ReadLine());
Console.Write("Ответ:", x - g);
}
}
}
Console.Write("Введите число:");
short x = Convert.ToInt16(Console.ReadLine());

Console.Write("Умножить или разделить или прибавить или уменьшить?:");
string bebra = Console.ReadLine();
if (bebra == "1")
{
Console.Write("Выбери число:");
short d = Convert.ToInt16(Console.ReadLine());
Console.Write("Ответ:" + (x * d));
}

if (bebra == "2")
{
Console.Write("Выберите число.:");
short e = Convert.ToInt16(Console.ReadLine());
Console.Write("Ответ:" + (x / e));
if (bebra == "3")
{
System.Console.Write("Напиши число.:");
int f = Convert.ToInt32(Console.ReadLine());
Console.Write("Ответ:" + (x + f));
if (bebra == "4")
{
System.Console.Write("Число дай:");
int g = Convert.ToInt32(Console.ReadLine());
Console.Write("Ответ:", x - g);
}
}
}
this is your code, formatted can you see the error?
DimOn4ik
DimOn4ikOP16mo ago
no
Pobiega
Pobiega16mo ago
Really?
TheRanger
TheRanger16mo ago
what's the issue anyway? what are u complaining about?
Pobiega
Pobiega16mo ago
I'll give you a hint, look at where your bebra == 3 and bebra == 4 if statements are located
DimOn4ik
DimOn4ikOP16mo ago
everything seems to be the same
Pobiega
Pobiega16mo ago
what do you mean by that?
DimOn4ik
DimOn4ikOP16mo ago
I don't see the error. They seem to be the same
Pobiega
Pobiega16mo ago
Look at the lines for bebra 1 and 2, then compare to 3 and 4 Do you really not see a difference?
DimOn4ik
DimOn4ikOP16mo ago
Really this is a very stupid mistake Thank you
Pobiega
Pobiega16mo ago
Did you figure it out? I'm confused
DimOn4ik
DimOn4ikOP16mo ago
Yes. Thank you, I've been on the Internet for half an hour to figure out what the error is
Pobiega
Pobiega16mo ago
Good. If and else isn't really the best choice here A switch would be better
DimOn4ik
DimOn4ikOP16mo ago
I know. I watch the course and study
Pobiega
Pobiega16mo ago
Okay.
DimOn4ik
DimOn4ikOP16mo ago
and is it possible to somehow make the cat, after its completion, start again?
Pobiega
Pobiega16mo ago
yes, use a loop
DimOn4ik
DimOn4ikOP16mo ago
is there an example?
Pobiega
Pobiega16mo ago
while(true)
{
// this code repeats forever
}
while(true)
{
// this code repeats forever
}
when you want to stop the loop, type break;
DimOn4ik
DimOn4ikOP16mo ago
should I write this at the beginning of the line or at the end?
Pobiega
Pobiega16mo ago
? break goes on its own line its a line of its own
DimOn4ik
DimOn4ikOP16mo ago
and what should I write at the end to start with a new line
Pobiega
Pobiega16mo ago
I don't understand what your are asking to be honest
DimOn4ik
DimOn4ikOP16mo ago
Okay.Thank you
Denis
Denis16mo ago
I suggest formatting your code correctly. The way you have it right now is very difficult to read and understand. To quickly format your code use the following shortcut: Ctrl K, D. This means that you hold Ctrl, press and release K and while still holding Ctrl press D. After that release Ctrl.
Советую правильно форматировать код. То что в скриншоте трудно прочитать и тем более понять. Для быстрой отформатировки кода можно использовать сокращение Ctrl K, D. Это значит что держа Ctrl нужно нажать и отпустить К, а потом (ещё держа Ctrl) нажать D. После этого можно отпустить и Ctrl.
Accord
Accord16mo 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.
Want results from more Discord servers?
Add your server