My code won't work (uhm total beginner here).

InternetSwag

Expert Member
Joined
Jan 24, 2012
Messages
3,955
Reaction score
329
Location
Cape Town
I'm trying to follow this video https://www.youtube.com/watch?v=Yj0G5UdBJZw&list=UU1MwJy1R0nGQkXxRD9p-zTQ to learn some stuff.

But I can't get the console command prompt to show up with the text.

This is where I am so far, please help me fix this.

PHP:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// HelloWorld
namespace JerrysCoolApp
{
    //Class (contains functionality)
    class Program
    {
        // Function (entry point)
        static void Main(string[] args)
        {
            String jerryString = "Hello this is Jerrys String"; 
            
            // Starting Point of everything
            Console.WriteLine("jerryString";)
        }
    }
}
 
I got stuck again. It's supposed to give me a command prompt, but I just get errors. Any help?

PHP:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// HelloWorld
namespace JerrysCoolApp
{
    //Class (contains functionality)
    class Program
    {
        // Function (entry point)
        static void Main(string[] args)
        {
            Console.WriteLine("Type a number, any number?");
            ConsoleKeyInfo keyInfo = Console.ReadKey();
            
            if( keyInfo.KeyChar == 'a');
            (
                Console.WriteLine("That is not a number! KNOCK IT OFF NOW!");
            )


            Console.WriteLine("Did you type {0}", keyInfo.KeyChar.ToString());
        }
    }
}
 
Code:
 Console.WriteLine("Type a number, any number?"); 
            ConsoleKeyInfo keyInfo = Console.ReadKey();

      if (keyInfo.KeyChar == 'a')
      {
        Console.WriteLine("That is not a number! KNOCK IT OFF NOW!");
      }


      Console.WriteLine("Did you type {0}", keyInfo.KeyChar.ToString());

(= {
) = }

no need for a ; by the if statement.
 
Two things. Saying "it's broken" doesn't help much. What are they actual error messages being thrown by your IDE? If you want to learn how to code, it's super important that you learn to listen to your IDE.

So you have a bunch of errors at compile-time, all of which Visual Studio will identify for you.

Your if-statement has syntax errors.

static void Main(string[] args)
{
Console.WriteLine("Type a number, any number?");
ConsoleKeyInfo keyInfo = Console.ReadKey();

if (keyInfo.KeyChar == 'a')
{
Console.WriteLine("That is not a number! KNOCK IT OFF NOW!");
}


Console.WriteLine("Did you type {0}", keyInfo.KeyChar.ToString());
}
 
Code:
 Console.WriteLine("Type a number, any number?"); 
            ConsoleKeyInfo keyInfo = Console.ReadKey();

      if (keyInfo.KeyChar == 'a')
      {
        Console.WriteLine("That is not a number! KNOCK IT OFF NOW!");
      }


      Console.WriteLine("Did you type {0}", keyInfo.KeyChar.ToString());

(= {
) = }

no need for a ; by the if statement.

Yesssss it works! Thank you!
 
Two things. Saying "it's broken" doesn't help much. What are they actual error messages being thrown by your IDE? If you want to learn how to code, it's super important that you learn to listen to your IDE.

So you have a bunch of errors at compile-time, all of which Visual Studio will identify for you.

Your if-statement has syntax errors.

Actually its better to read the code, before the IDE tells you whats broken. Else you will always be reliant on it.
 
Two things. Saying "it's broken" doesn't help much. What are they actual error messages being thrown by your IDE? If you want to learn how to code, it's super important that you learn to listen to your IDE.

So you have a bunch of errors at compile-time, all of which Visual Studio will identify for you.

Your if-statement has syntax errors.

I don't understand a few things you said, but I get these errors when I use the ( instead of {
Untitled.jpg

I guess the next step is to find out how to use those errors to fix things and find out when to use { and when to use (
 
I don't understand a few things you said, but I get these errors when I use the ( instead of {
View attachment 139506

I guess the next step is to find out how to use those errors to fix things and find out when to use { and when to use (

Just remember that when you're doing if statements you wrap the expression in ( x ) i.e. if (b>c) then the parenthesis follows { }
 
Just remember that when you're doing if statements you wrap the expression in ( x ) i.e. if (b>c) then the parenthesis follows { }

@OP, Maybe start referring to { } as code braces, so that you can remember to use them only when they will contain code, not when creating arrays [], or comparisons and arguments ().
 
@OP, Maybe start referring to { } as code braces, so that you can remember to use them only when they will contain code, not when creating arrays [], or comparisons and arguments ().

Yeah braces sorry, or as my friend calls them gullwings.
 
A ; after if condition renders that if moot. Also i find that lots of devs even 'experienced' ones dont read the erros msgs. They justvsee the error and then look at the code to figure out what is wrong. You need to read the error msg and understand what it means. Andthen look at your code in that context. Resharper helps a lot in that regard. Dunno how ppl code efectively without R#.
 
A ; after if condition renders that if moot. Also i find that lots of devs even 'experienced' ones dont read the erros msgs. They justvsee the error and then look at the code to figure out what is wrong. You need to read the error msg and understand what it means. Andthen look at your code in that context. Resharper helps a lot in that regard. Dunno how ppl code efectively without R#.

really
 
Ehh, trying to figure out this coding error myself.

I got the error 1. Expected class, delegate, enum, interface, or struct. It underlines my void or static void.

PHP:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// HelloWorld
namespace JerrysCoolApp
{
    //Class (contains functionality)
    class Program
    {
        // Function (entry point)
        static void Main(string[] args)
        {
            Console.WriteLine("Type a number, any number?");
            ConsoleKeyInfo keyInfo = Console.ReadKey();

            PrintFooToScreen();

            if (keyInfo.KeyChar == 'a')
            {
                Console.WriteLine("That is not a number! KNOCK IT OFF NOW!");
            }
            else 
            {  
                Console.WriteLine("Did you type {0}", keyInfo.KeyChar.ToString());
           }
        }
        /// <summary>
        /// All this function does is print Foo to the screen
        /// </summary>
        static void PrintFooToScreen()
        {
            Console.WriteLine("Foo");
        }
    }
    static void PrintFooToScreen100times()
    {
        for(int counter=0); counter <= 100; counter++)
    (
        PrintFooToScreen{}; 
    )



}
}

So without telling me exactly what I did wrong, can you teach me how to read this error message and understand what I need to change?

static void PrintFooToScreen100times() - void is underlined with a red line.
 
Ehh, trying to figure out this coding error myself.

I got the error 1. Expected class, delegate, enum, interface, or struct. It underlines my void or static void.

PHP:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// HelloWorld
namespace JerrysCoolApp
{
    //Class (contains functionality)
    class Program
    {
        // Function (entry point)
        static void Main(string[] args)
        {
            Console.WriteLine("Type a number, any number?");
            ConsoleKeyInfo keyInfo = Console.ReadKey();

            PrintFooToScreen();

            if (keyInfo.KeyChar == 'a')
            {
                Console.WriteLine("That is not a number! KNOCK IT OFF NOW!");
            }
            else 
            {  
                Console.WriteLine("Did you type {0}", keyInfo.KeyChar.ToString());
           }
        }
        /// <summary>
        /// All this function does is print Foo to the screen
        /// </summary>
        static void PrintFooToScreen()
        {
            Console.WriteLine("Foo");
        }
    }
    static void PrintFooToScreen100times()
    {
        for(int counter=0); counter <= 100; counter++)
    (
        PrintFooToScreen{}; 
    )



}
}

So without telling me exactly what I did wrong, can you teach me how to read this error message and understand what I need to change?

static void PrintFooToScreen100times() - void is underlined with a red line.

You've got problems with brackets. Just double check them.
 
Top
Sign up to the MyBroadband newsletter
X