C
C#10mo ago
DimOn4ik

❔ Please help me write code

///
35 Replies
DimOn4ik
DimOn4ik10mo ago
I don't understand what is wrong here
Pobiega
Pobiega10mo ago
please dont post screenshots of code. $code
MODiX
MODiX10mo 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
DimOn4ik10mo 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
Pobiega10mo ago
Read the instructions again You missed the important part
DimOn4ik
DimOn4ik10mo ago
That's what I wrote, because I don't understand what's wrong here
Pobiega
Pobiega10mo ago
$codegif
DimOn4ik
DimOn4ik10mo ago
I don't spell it that way
Pobiega
Pobiega10mo 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
DimOn4ik10mo ago
no
Pobiega
Pobiega10mo ago
Really?
TheRanger
TheRanger10mo ago
what's the issue anyway? what are u complaining about?
Pobiega
Pobiega10mo ago
I'll give you a hint, look at where your bebra == 3 and bebra == 4 if statements are located
DimOn4ik
DimOn4ik10mo ago
everything seems to be the same
Pobiega
Pobiega10mo ago
what do you mean by that?
DimOn4ik
DimOn4ik10mo ago
I don't see the error. They seem to be the same
Pobiega
Pobiega10mo ago
Look at the lines for bebra 1 and 2, then compare to 3 and 4 Do you really not see a difference?
DimOn4ik
DimOn4ik10mo ago
Really this is a very stupid mistake Thank you
Pobiega
Pobiega10mo ago
Did you figure it out? I'm confused
DimOn4ik
DimOn4ik10mo ago
Yes. Thank you, I've been on the Internet for half an hour to figure out what the error is
Pobiega
Pobiega10mo ago
Good. If and else isn't really the best choice here A switch would be better
DimOn4ik
DimOn4ik10mo ago
I know. I watch the course and study
Pobiega
Pobiega10mo ago
Okay.
DimOn4ik
DimOn4ik10mo ago
and is it possible to somehow make the cat, after its completion, start again?
Pobiega
Pobiega10mo ago
yes, use a loop
DimOn4ik
DimOn4ik10mo ago
is there an example?
Pobiega
Pobiega10mo ago
while(true)
{
// this code repeats forever
}
while(true)
{
// this code repeats forever
}
when you want to stop the loop, type break;
DimOn4ik
DimOn4ik10mo ago
should I write this at the beginning of the line or at the end?
Pobiega
Pobiega10mo ago
? break goes on its own line its a line of its own
DimOn4ik
DimOn4ik10mo ago
and what should I write at the end to start with a new line
Pobiega
Pobiega10mo ago
I don't understand what your are asking to be honest
DimOn4ik
DimOn4ik10mo ago
Okay.Thank you
Denis
Denis10mo 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
Accord10mo 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.