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

How does Modulo work? I'm doing the codeacademy course, slide 20.

It says that, "When % is placed between two numbers, the computer will divide the first number by the second, and then return the remainder of that division.

So if we do 23 % 10, we divide 23 by 10 which equals 2 with 3 left over. So 23 % 10 evaluates to 3."

23/10 = 2.3
does that mean Modulo takes the 0.3 of the 2.3 and just throws away the 2?

It can't be though? Since it lists that "17 % 5 evaluates to 2"
17/5 = 3.4

Help? Please.

I was able to complete the activity, but I want to understand how Modulo works.
 
How does Modulo work? I'm doing the codeacademy course, slide 20.

It says that, "When % is placed between two numbers, the computer will divide the first number by the second, and then return the remainder of that division.

So if we do 23 % 10, we divide 23 by 10 which equals 2 with 3 left over. So 23 % 10 evaluates to 3."

23/10 = 2.3
does that mean Modulo takes the 0.3 of the 2.3 and just throws away the 2?

It can't be though? Since it lists that "17 % 5 evaluates to 2"
17/5 = 3.4

Help? Please.

I was able to complete the activity, but I want to understand how Modulo works.

Modulo is not the decimal part, its the remainder.

For example, 17/5 is 3 remainder 2 (hence why it returns 2). Why? Cause 5 goes into 17, 3 times (15/5) and there is a remainder of 2 (17-15)
 
Modulo is not the decimal part, its the remainder.

For example, 17/5 is 3 remainder 2 (hence why it returns 2). Why? Cause 5 goes into 17, 3 times (15/5) and there is a remainder of 2 (17-15)

Oh! Ohhhhhhhhhhhh!

13 % 7
13/7 = 1.8
7-1=6

13 % 7 = 6?

Yessss thank you!
 
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)
   [B] class Program
    {[/B]
        // 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");
        }
    [B]}[/B]
    [B]static void PrintFooToScreen100times()[/B]
    {
        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.

The bold bits are your first clues. The compiler is telling you that it found a method PrintFooToScreen100times but it was actually expecting to find "Expected class, delegate, enum, interface, or struct"

So your first thought should be that something is not where it's supposed to be. So like others mentioned this is common when you don't close off your brackets properly. In this case that function is currently sitting outside the class definition which is causing the compiler to complain.
 
The bold bits are your first clues. The compiler is telling you that it found a method PrintFooToScreen100times but it was actually expecting to find "Expected class, delegate, enum, interface, or struct"

So your first thought should be that something is not where it's supposed to be. So like others mentioned this is common when you don't close off your brackets properly. In this case that function is currently sitting outside the class definition which is causing the compiler to complain.

What is a 'class definition?'
 
What is a 'class definition?'

K I'm just going to type in complete layman's terms :)

So in object orientation based programming we model everything in terms of "Objects". In order to create an object we need to provide the computer with a blueprint so that it knows how to create a particular object. We call these blueprints "Classes". An object is then an instance of this class.

So a blueprint of a car would be a class.
The actual finished car would be an instance of that class known as an object.

Following this example:

A class is typically defined in its own file as follows the syntax of

class Car {

}

This is known as the class definition. In this section of code is where we define all the properties and methods that a car will have.

Hope this helps :)

EDIT:

As the above post says. You're jumping right into code without understanding what's going on. First go and learn the basics of Object Orientation and then go from there.
 
Last edited:
Start slowly dude, you are all over the show :

http://www.completecsharptutorial.com/
Thanks, I appreciate the link! You're right.

I have so many links atm that have been given to me, I need to slowly work through them all to understand this.
Currently doing Codeacademy's Javascript cause everyone told me it's similar to C#.
I also have an e-book, microsoft virual academy links open and several others that have been open for like 3 days now. Programming is overwhelming.
K I'm just going to type in complete layman's terms :)

So in object orientation based programming we model everything in terms of "Objects". In order to create an object we need to provide the computer with a blueprint so that it knows how to create a particular object. We call these blueprints "Classes". An object is then an instance of this class.

So a blueprint of a car would be a class.
The actual finished car would be an instance of that class known as an object.

Following this example:

A class is typically defined in its own file as follows the syntax of

class Car {

}

This is known as the class definition. In this section of code is where we define all the properties and methods that a car will have.

Hope this helps :)

EDIT:

As the above post says. You're jumping right into code without understanding what's going on. First go and learn the basics of Object Orientation and then go from there.

Man, I have new respect for programmers after this thread. I mean, not that I ever disrespected programmers, I just never knew how damn much you guys actually need to learn!

Thanks a lot for your help.
 
Thanks, I appreciate the link! You're right.

I have so many links atm that have been given to me, I need to slowly work through them all to understand this.
Currently doing Codeacademy's Javascript cause everyone told me it's similar to C#.
I also have an e-book, microsoft virual academy links open and several others that have been open for like 3 days now. Programming is overwhelming.


Man, I have new respect for programmers after this thread. I mean, not that I ever disrespected programmers, I just never knew how damn much you guys actually need to learn!

Thanks a lot for your help.

You probably mean Java, not Javascript. Two completely different languages so don't be fooled by the names :)
 
You probably mean Java, not Javascript. Two completely different languages so don't be fooled by the names :)

I don't even know.

mind-blown.jpg

What my head feels like after this thread.
 

Attachments

  • mind-blown.jpg
    mind-blown.jpg
    37.3 KB · Views: 56
I don't even know.

mind-blown.jpg

What my head feels like after this thread.

If you are working on something, and both "" and '' works, the thing that worked fine 10 minutes ago no longer works, and just gives you a general sense of frustration, that will be javascript :D
 
So because 10 can go into 30 3 times, there is no 'minus' section.

I got it now I think.

My head hurts though.

Just practice and you'll be fine :) Modulus has its uses but you're not going to use it at this stage. Rather start at the basics and build up.
 
Start some bitwise that's always fun, in a sadistic way.
 
K I'm just going to type in complete layman's terms :)

So in object orientation based programming we model everything in terms of "Objects". In order to create an object we need to provide the computer with a blueprint so that it knows how to create a particular object. We call these blueprints "Classes". An object is then an instance of this class.

So a blueprint of a car would be a class.
The actual finished car would be an instance of that class known as an object.

Following this example:

A class is typically defined in its own file as follows the syntax of

class Car {

}

This is known as the class definition. In this section of code is where we define all the properties and methods that a car will have.

Hope this helps :)

EDIT:

As the above post says. You're jumping right into code without understanding what's going on. First go and learn the basics of Object Orientation and then go from there.
ROFL I remember the first time the concept of classes and objects was explained to me. My brain melted.

To this day I stand by my opinion that this isn't something that is easily explainable when a new student starts programming. Instead this is something they need to see for themselves. It is like when you look at a picture of a candlestick long enough and it suddenly resolves itself into two faces. Mess about with code long enough and how classes and objects relate to one another becomes obvious.
 
So because 10 can go into 30 3 times, there is no 'minus' section.

I got it now I think.

My head hurts though.
The modulus operator will give you the remainder. If you divide 30 by 10 you get exactly 3, with nothing left over. So with nothing left over your answer is 0.


So modulus says:

30/10=3 with 0 left over

therefore answer is 0.
 
Top
Sign up to the MyBroadband newsletter
X