Programming for Idiots (C#) - Take 2

12/17/2010 20:01 DragonHeart#31
Quote:
Originally Posted by tanelipe View Post
People don't read stickys (judging by the amount of rule-breakers this forum has) so it's better to just leave it amongst normal threads.
No, people don't read rules cause they are boring, useless and most likely a freakin wall of text. And the egies don't even understand what it says anyways.
12/18/2010 03:53 InfamousNoone#32
@ Above: I agree with you. In all honesty, nobody reads the rules until they start getting bans or warnings.

Well it's no problem if this isn't stickied. My other one containing videos is stickied, and I added a link noting that it was superseded by this one.

Anyhow, I'll try to get up a lesson on structures (I'm going to break this down into two parts). If anyone cares why I'm breaking it down into two parts, in one, I'm going to talk about using structures the way I do, and in the other, I'm going to talk about general-case scenarios as to how they can be used (but I wouldn't use them as such).
12/18/2010 09:01 co_george#33
ty bud, e*pvp should thank you 4ever for your great releases and your willing to help this forum. ty again! im learning your guide right now and you know what? you explained this shit very well so everyone can learn it :) thanks again. i would rape the thanks button if i could thank you more than one time :D

Later edit: I think is a problem at lesson five - bool values

Code:
            if (condition)
            {
                // code to execute if condition is true
            }
            else if (condition2)
            {
                // code to execute if condition is false
                // and condition2 is true
            }
            else
            {
                // code to execute if condition is false
                // and condition2 is false
            }
i think you need to add the "if" for the 3rd condition also (where the code execute if the both conditions are false). ifi let it like it is right now without the "if" at the 3rd statement, error pop up but if i add "if" everything works fine. here's the code


Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Tell me how much money you have in your pockets");
            double amount = double.Parse(Console.ReadLine());
            if (amount > 2000.00)
            {
                Console.WriteLine("You are rich");
                Console.ReadLine();
            }
            else if (amount == 2000.00)
            {
                Console.WriteLine("You are fine");
                Console.ReadLine();
            }
            else if (amount < 2000.00)
            {
                Console.WriteLine("You are poor");
                Console.ReadLine();
            }
            
        }

    }
}
tell me if i am wrong!!!
12/18/2010 11:15 Korvacs#34
I was going to sticky this once Unit 2/3 had been completed so that there was alot of content available.
12/18/2010 11:42 _Emme_#35
Quote:
Originally Posted by co_george View Post


[code]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Tell me how much money you have in your pockets");
double amount = double.Parse(Console.ReadLine());
if (amount > 2000.00)
{
Console.WriteLine("You are rich");
Console.ReadLine();
}
else if (amount == 2000.00)
{
Console.WriteLine("You are fine");
Console.ReadLine();
}
else if (amount < 2000.00)
{
Console.WriteLine("You are poor");
Console.ReadLine();
}

}

}
}
You can use ternary operations for calls like that. Here's an example:

Code:
static void Main(string[] args)
        {
            Console.WriteLine("Please insert how much money you have in your pockets");
            Console.Write("Amount: ");
            double amount = double.Parse(Console.ReadLine());
            Console.WriteLine(amount > 2000 ? "You are rich!" : "You are poor!");
        }
Ternary operation - Wikipedia, the free encyclopedia
12/18/2010 11:56 co_george#36
Thats really awesome Emme but i just started with C# and i dont know very much about, just following Hybrid's guides and trying to understand them (now i'm stuck at Lesson 6 - While Loops). I still have a question. My shitty code it's actually working fine and there's not problem writing the code like mine or like you isnt it? I know your code it's smaller just 4 codelines but doesnt really matter if i do in my way. What i mean it's correct what i done or not ?:)
12/18/2010 12:40 _Emme_#37
Quote:
Originally Posted by co_george View Post
Thats really awesome Emme but i just started with C# and i dont know very much about, just following Hybrid's guides and trying to understand them (now i'm stuck at Lesson 6 - While Loops). I still have a question. My shitty code it's actually working fine and there's not problem writing the code like mine or like you isnt it? I know your code it's smaller just 4 codelines but doesnt really matter if i do in my way. What i mean it's correct what i done or not ?:)
I see.

The way you're doing it is like

Code:
if (amount > 2000.00)
{
Console.WriteLine("You are rich");
Console.ReadLine();
}
else if (amount == 2000.00)
{
Console.WriteLine("You are fine");
Console.ReadLine();
}
else if (amount < 2000.00)
{
Console.WriteLine("You are poor");
Console.ReadLine();
}

but if you want it done that way, you should do:

Code:
static void Main(string[] args)
{
Console.WriteLine("Enter the amount of money in your pockets");
Console.Write("Amount: ");
double amount = double.Parse(Console.ReadLine());

if(amount > 2000) // Checks if amount is 2001 or above
 Console.WriteLine("You are rich");
else if(amount < 2000) // Checks if amount is 1999 or under
 Console.WriteLine("You are poor");
else //Else if amount isn't under 1999 or over 2001, it is 2000.
 Console.WriteLine("You are fine");

Console.ReadLine();

}
12/18/2010 12:45 InfamousNoone#38
Quote:
Originally Posted by co_george View Post
ty bud, e*pvp should thank you 4ever for your great releases and your willing to help this forum. ty again! im learning your guide right now and you know what? you explained this shit very well so everyone can learn it :) thanks again. i would rape the thanks button if i could thank you more than one time :D

Later edit: I think is a problem at lesson five - bool values

Code:
            if (condition)
            {
                // code to execute if condition is true
            }
            else if (condition2)
            {
                // code to execute if condition is false
                // and condition2 is true
            }
            else
            {
                // code to execute if condition is false
                // and condition2 is false
            }
i think you need to add the "if" for the 3rd condition also (where the code execute if the both conditions are false). ifi let it like it is right now without the "if" at the 3rd statement, error pop up but if i add "if" everything works fine. here's the code


Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Tell me how much money you have in your pockets");
            double amount = double.Parse(Console.ReadLine());
            if (amount > 2000.00)
            {
                Console.WriteLine("You are rich");
                Console.ReadLine();
            }
            else if (amount == 2000.00)
            {
                Console.WriteLine("You are fine");
                Console.ReadLine();
            }
            else if (amount < 2000.00)
            {
                Console.WriteLine("You are poor");
                Console.ReadLine();
            }
            
        }

    }
}
tell me if i am wrong!!!
What you did was absolutely correct. Let's take a look at what you said. You wanted to know why this was wrong:
Code:
            Console.WriteLine("Tell me how much money you have in your pockets");
            double amount = double.Parse(Console.ReadLine());
            if (amount > 2000.00)
            {
                Console.WriteLine("You are rich");
                Console.ReadLine();
            }
            else if (amount == 2000.00)
            {
                Console.WriteLine("You are fine");
                Console.ReadLine();
            }
            else (amount < 2000.00)
            {
                Console.WriteLine("You are poor");
                Console.ReadLine();
            }
The reason it is wrong is because, is because the "else" case should only be used when all above conditions are false. What you were trying to do, was specify another condition to check: (amount < 2000.00), so for this we would use else if as you had done :).

Something to think about though is
Code:
            Console.WriteLine("Tell me how much money you have in your pockets");
            double amount = double.Parse(Console.ReadLine());
            if (amount > 2000.00)
            {
                Console.WriteLine("You are rich");
                Console.ReadLine();
            }
            else if (amount == 2000.00)
            {
                Console.WriteLine("You are fine");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("You are poor");
                Console.ReadLine();
            }
Would work perfectly fine! Because, above your final else statement, we check if amount > 2000.00 and amount == 2000.00, and if both of these are false -- then amount < 2000.00 must be true!

Quote:
Originally Posted by Korvacs View Post
I was going to sticky this once Unit 2/3 had been completed so that there was alot of content available.
Thanks a lot Jack for the support. Really appreciated.

Quote:
Originally Posted by EmmeTheCoder View Post
You can use ternary operations for calls like that. Here's an example:

Code:
static void Main(string[] args)
        {
            Console.WriteLine("Please insert how much money you have in your pockets");
            Console.Write("Amount: ");
            double amount = double.Parse(Console.ReadLine());
            Console.WriteLine(amount > 2000 ? "You are rich!" : "You are poor!");
        }
Ternary operation - Wikipedia, the free encyclopedia
While using the ternary operator is simpler, it is not easier for early programmers to understand. The early-on unit-one series' goal isn't to create good programming habits, but to familiarize new programmers with the language.

Quote:
Originally Posted by co_george View Post
Thats really awesome Emme but i just started with C# and i dont know very much about, just following Hybrid's guides and trying to understand them (now i'm stuck at Lesson 6 - While Loops). I still have a question. My shitty code it's actually working fine and there's not problem writing the code like mine or like you isnt it? I know your code it's smaller just 4 codelines but doesnt really matter if i do in my way. What i mean it's correct what i done or not ?:)
You're absolutely right. At this point in time, it doesn't matter how you do it as long as you understand what you are doing!.

Directed more at Emme, not George:
However, it should be noted, your code and Emme's code carries a significant difference. Your code checks for 3 things equality, greater than, & lesser than, using the ternary operator as Emme has done is checking for greater than and if not, lesser than or equal to. So NO. One ternary operation in this case is not applicable and wrong. You can tell this is wrong because Emme's code will show two outputs on the console (poor, or rich), while yours shows three (poor, rich and fine).

Edit:
Added (Unit Two) Lesson Three - Enumerations.
Also, and edit to my last remarks in this post.
12/18/2010 13:23 _Emme_#39
Here's a pretty good list you could use to exam stages on the road of learning programming. Don't use it to see yourself as a bad programmer as you might not qualify on all the points, but use it now and then to see that you're progressing.

[Only registered and activated users can see links. Click Here To Register...]
12/18/2010 13:26 co_george#40
Thank you mate for making me understand! I'm surprised how much willing to help you are. :D
Same goes for you Emme
12/18/2010 13:32 InfamousNoone#41
Quote:
Originally Posted by EmmeTheCoder View Post
Here's a pretty good list you could use to exam stages on the road of learning programming. Don't use it to see yourself as a bad programmer as you might not qualify on all the points, but use it now and then to see that you're progressing.

[Only registered and activated users can see links. Click Here To Register...]
Skimming over that link, it seems more targeted at C/C++ programmers rather than higher-level language programmers (i.e. Java, C#, et cetra).

Edit:
No problem, all in a days work.
12/18/2010 19:02 hok30#42
Quote:
Originally Posted by InfamousNoone View Post
Skimming over that link, it seems more targeted at C/C++ programmers rather than higher-level language programmers (i.e. Java, C#, et cetra).

Edit:
No problem, all in a days work.
Holy crap. How are you still here? I used this tutorial like a year ago. (video)
12/18/2010 23:58 InfamousNoone#43
Quote:
Originally Posted by hok30 View Post
Holy crap. How are you still here? I used this tutorial like a year ago. (video)
Due to be quitting retail CO, a lot of spare time has opended up for me (and not to mention, now I'm on winter breaK). So, I've got a lot of time, with a whole lot of nothing tot do. So, I ifgure, might as well do something productive, eh?

Edit:
Added Lesson Four - Bit Operations and Enumerations (II).
12/19/2010 03:52 xScott#44
wonder if you could, or if your intending to anyway, talk about stackalloc, and using out & ref. <--- tis completely confused me, learning vb as my first language :S

these bitwise operations finally put my knowledge of truth tables and logic gates to some use, haha.
12/19/2010 04:02 InfamousNoone#45
Quote:
Originally Posted by xScott View Post
wonder if you could, or if your intending to anyway, talk about stackalloc, and using out & ref. <--- tis completely confused me, learning vb as my first language :S
No problem. I can cover ref/out in the next lesson -- but, I'm not going to cover stackalloc until "Welcome to the darkside".

Edit:
Lesson Five - Out, Ref and Nullable Types