✅ need help with a basic code
nt x= 6
; int y = 7;
Console.WriteLine("what is x+y?");
string input = Console.ReadLine();
int answer;
if (int.TryParse(input, out answer)) {
if (answer == x+y) {
Console.WriteLine("correct");
{
else
}
Console.WriteLine("wrong, right answer is:)" + (x+y));
{
else
}
Console.WriteLine("enter a valid num");
Console.ReadLine();
24 Replies
what is the mistake here
Would you mind fixing the formatting first? $code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/d
And you have some invalid syntax going on here due to bracket placement
when formatted correctly, the errors are quite easy to spot

yes i noticed thanks
btw can i ask anotehr question
yes
namespace MyApp
{
internal class Program
{
static void Main(string[] args)
{
int x = 6;
int y = 7;
Console.WriteLine("what is x + y?");
string input = Console.ReadLine();
int answer;
if (int.TryParse(input, out answer))
{
if (answer == x + y)
{
Console.WriteLine("correct");
}
else
{
Console.WriteLine("wrong, right answer is: " + (x + y));
} } else { Console.WriteLine("enter a valid number"); string again = Console.ReadLine(); } } } } thats the code
} } else { Console.WriteLine("enter a valid number"); string again = Console.ReadLine(); } } } } thats the code
$codegif
discord supports code blocks
use them
i want it to when i answer a wrong number to make it continue like an infinite loop iuntil its right
sure
and it stops on the screen at wrong
you'd need to use a loop for that
what is x + y?
6
wrong, right answer is: 13
look it dosent ask anymore questiions
and code should be
thats because you dont have any loop in your code
it wont loop unless you use a loop
yeah but i HAVE ELSE AND IF
sure
neither of those are loops
while
, for
and do...while
are loopsoh yeah i understood my mistake i didnt read the code good
mb , thanks bro
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View