Sign in to follow this  

Am I Ready?

This topic is 2356 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been reading through a book on C# and i was wondering if you think i am ready to start writing extremely basic programs. I have been doing the examples in the book and trying not to move on in the book untill i am reasonably comfortable with what i have just read. (Also, this may sound like a noob question, but what programs should i start off with?)

Thank you :)

Share this post


Link to post
Share on other sites
[quote name='melloorr' timestamp='1312247109' post='4843381']
I have been reading through a book on C# and i was wondering if you think i am ready to start writing extremely basic programs.[/quote]
Yes. Give it a try!

Share this post


Link to post
Share on other sites
[quote name='melloorr' timestamp='1312247109' post='4843381']
(Also, this may sound like a noob question, but what programs should i start off with?)
Thank you :)
[/quote]

Depends on what you've learned so far. Off the top of my head:

Some very basic string manipulation, to practice input/output, loops, and a few standard library methods:

1. Ask for a name, user enters a name, output the the name in all capital letters
2. As above, except output each letter separately then pause until the user hits the enter key
3. As above, but output the letters backwards, or in alphabetical order, or shuffle them randomly
4. Create a simple database, where the user enters names and phone numbers. If the user hits enter without entering a name, ask for a name, and then output the associated phone number previously entered
5. As above, but save the name/number data to a text file.

A simple game might be a guess-the number, where after each guess the program outputs "higher" or "lower" until the user guesses correctly (or only give the user a fixed # of guesses before loosing).

Share this post


Link to post
Share on other sites
A cool idea would also be a simple text andventure. Using files to drive the game instead of hardcoding it. That should keep you busy.

Share this post


Link to post
Share on other sites
One of my favorites:

XXXXXXXX
AAAXXXXX
XXAAAXXX
XXXXAXXX
XXAAAXXX
XXAXXXXX
XXAAAAAA
XXXXXXXX

Put the above 8x8 matrix in the text file. Starting at the first A, write a generic program to find a way from the the A in the first column to the A in the last column. Of course, you'll have to assume that there are no loops and first and last row only has one A each to keep it simple. At the end you must print out the number of A's to get to the end. Recursion is a very important concept and I think this is a very good exercise for that.

Share this post


Link to post
Share on other sites
A text based calculator might work pretty well. You learn how to handle inputs pretty well from it in my opinion and you can do it very early on while learning to program.

Share this post


Link to post
Share on other sites
[quote name='melloorr' timestamp='1312247109' post='4843381']I have been reading through a book on C# and i was wondering if you think i am ready to start writing extremely basic programs. I have been doing the examples in the book and trying not to move on in the book untill i am reasonably comfortable with what i have just read. (Also, this may sound like a noob question, but what programs should i start off with?)[/quote]
Ready are you, young Jedi! You could start with a text-based Higher or Lower card game. This would involve making both a data structure to represent a single card and one for representing a deck (which would manage 52 card structures), being able to represent each of them on the screen (for example "9C" for "9 of clubs"), and compare them to find out which has the higher value -- all in all a good, little beginner's project that will teach you some basic principals of game programming.

Share this post


Link to post
Share on other sites
[quote name='melloorr' timestamp='1312247109' post='4843381']
I have been reading through a book on C# and i was wondering if you think i am ready to start writing extremely basic programs. I have been doing the examples in the book and trying not to move on in the book untill i am reasonably comfortable with what i have just read. (Also, this may sound like a noob question, but what programs should i start off with?)

Thank you :)
[/quote]

Dude you don't realy learn from reading you learn from writing the code.. Just give it a try!
Myself when i started learning java i tried to make my own swing applications and i had great fun with it also and it helped me learn alot!
So realy my advice is just go for the console applications if you never realy coded before.

Share this post


Link to post
Share on other sites
Another good exercise is to read in your own source file and output the comments in the file only and replace all the rest with spaces. This learns you somthing about state machines and file parsing, remeber that C# has // and /**/ as comment syntax.

Share this post


Link to post
Share on other sites
Never underestimate the educational value of Pong. Don't even worry about graphics yet, just learn how to clear the screen quickly, and redraw the paddle and ball with ascii characters.

As you learn new things like graphics, sound, or networking, you can add them to your Pong game... you can basically start at zero and (if you stick with it) incrementally improve things until you have a professional-looking game. Sticking with one game and improving it over time will also teach you a lot about code re-use, which plenty coders don't really grasp until they've been writing code for a year or two.

Share this post


Link to post
Share on other sites
Thanks for all your suggestions, i will try to attempt them all! :)

[quote name='laztrezort' timestamp='1312249203' post='4843390']

Depends on what you've learned so far. Off the top of my head:

Some very basic string manipulation, to practice input/output, loops, and a few standard library methods:

1. Ask for a name, user enters a name, output the the name in all capital letters
2. As above, except output each letter separately then pause until the user hits the enter key
3. As above, but output the letters backwards, or in alphabetical order, or shuffle them randomly
4. Create a simple database, where the user enters names and phone numbers. If the user hits enter without entering a name, ask for a name, and then output the associated phone number previously entered
5. As above, but save the name/number data to a text file.

A simple game might be a guess-the number, where after each guess the program outputs "higher" or "lower" until the user guesses correctly (or only give the user a fixed # of guesses before loosing).
[/quote]

I am having trouble with #2, I dont know how to do it, i have tried looking but i have found nothing yet :blink: Can anyone give me a hint on how i could do it please?

Share this post


Link to post
Share on other sites
[quote name='melloorr' timestamp='1312298914' post='4843632']
[quote name='laztrezort' timestamp='1312249203' post='4843390']
2. As above, except output each letter separately then pause until the user hits the enter key
[/quote]
I am having trouble with #2, I dont know how to do it, i have tried looking but i have found nothing yet :blink: Can anyone give me a hint on how i could do it please?
[/quote]

Hint: You can use a string like an array of chars.

Share this post


Link to post
Share on other sites
[quote name='Nypyren' timestamp='1312304840' post='4843661']
Hint: You can use a string like an array of chars.
[/quote]

Am i being stupid? I still can't do it :( All i can find is how to split string that have commas in, but none about splitting a word

Share this post


Link to post
Share on other sites
[quote name='melloorr' timestamp='1312309820' post='4843697']Am i being stupid? I still can't do it :( All i can find is how to split string that have commas in, but none about splitting a word[/quote]
No, you are not stupid; programming can be very difficult in the beginning when you are unfamiliar with even the most basic principals. If you list your program so far I may be able to give you a few guideline =)

Share this post


Link to post
Share on other sites
[quote name='Dragonion' timestamp='1312311748' post='4843715']
[quote name='melloorr' timestamp='1312309820' post='4843697']Am i being stupid? I still can't do it :( All i can find is how to split string that have commas in, but none about splitting a word[/quote]
No, you are not stupid; programming can be very difficult in the beginning when you are unfamiliar with even the most basic principals. If you list your program so far I may be able to give you a few guideline =)
[/quote]

This is what i have got for # 1 and 3:
[code]
using System;

class BasicProject1
{
static void Main()
{
string name, nameUp, nameBack;

Console.Write("Please enter your name: ");
name = Console.ReadLine();

nameUp = name;
nameUp = nameUp.ToUpper();
nameBack = name;

Console.WriteLine("Your name in capitals is: " + nameUp);

Console.Write("Your name backwards is: ");

for (int i = 0; i < nameBack.Length; i++)
{
Console.Write(nameBack[nameBack.Length -i - 1]);
}

Console.ReadLine();
}
}
[/code]

Share this post


Link to post
Share on other sites
[quote name='melloorr' timestamp='1312315360' post='4843744']This is what i have got for # 1 and 3:[/quote]
[code]using System;

class BasicProject1
{
static void Main()
{
string name, nameUp, nameBack;

Console.Write("Please enter your name: ");

name = Console.ReadLine();
nameUp = name.ToUpper(); // string.ToUpper returns a copy of the string so I merged the two lines
nameBack = name;

Console.WriteLine("Your name in capitals is: " + nameUp); // Good! Task #1 complete :)

// I am not going to solve #2 for you, but here is a tip:
// Console::ReadKey(Boolean) will read the next keystroke by the user, including function keys,
// and if you set the Boolean value to "true" it will not output the read character on the screen.

Console.Write("Your name backwards is: ");

// When you are dealing with strings (that fall into the category "things that may change at run-time")
// it is usually a good idea to assign its length to a local variable when accessing each character in turn
// before you start the for-loop like this:
//
// int i,n=nameBack.Length;
//
// for(i=0;i<n;i++)
// {
// ...
// }

for (int i = 0; i < nameBack.Length; i++)
{
Console.Write(nameBack[nameBack.Length -i - 1]);
}

Console.ReadLine();
}
}
[/code]

Share this post


Link to post
Share on other sites
Another hint for #2: Watch what happens in your loop that prints the name backwards. Put a breakpoint inside the loop and watch your output each time you step through the loop. It prints out one letter at a time, right? You should be able to add something else inside the loop which makes it wait in a similar way to the breakpoint (previous people have hinted how to do this).

Share this post


Link to post
Share on other sites
[quote name='Nypyren' timestamp='1312332426' post='4843858']
Another hint for #2: Watch what happens in your loop that prints the name backwards. Put a breakpoint inside the loop and watch your output each time you step through the loop. It prints out one letter at a time, right? You should be able to add something else inside the loop which makes it wait in a similar way to the breakpoint (previous people have hinted how to do this).
[/quote]

Thanks! I finally done it! Well im pretty sure i have :)

[code]using System;

class BasicProject1
{
static void Main()
{
string name, nameUp, nameBack;

// Task One

Console.Write("Please enter your name: ");
name = Console.ReadLine();

nameUp = name.ToUpper();
nameBack = name;

Console.WriteLine("Your name in capitals is: " + nameUp);

// Task Two

int s = name.Length;

for (int i = 0; i < s; i++)
{
Console.Write(name[i]);
Console.ReadKey(true);
continue;
}

// Task Three

Console.Write("\nYour name backwards is: ");

int n = nameBack.Length;

for (int i = 0; i < n; i++)
{
Console.Write(nameBack[nameBack.Length -i -1]);
}

Console.ReadLine();
}
}[/code]

Share this post


Link to post
Share on other sites
[quote name='melloorr' timestamp='1312334050' post='4843871']Thanks! I finally done it! Well im pretty sure i have :)[/quote]
Woohoo! Good job! =)

A couple of things:

1.[code]
for (int i = 0; i < s; i++)
{
Console.Write(name[i]);
Console.ReadKey(true);
continue; // this is redundant
}
[/code]
When the keyword [font="Courier New"]continue[/font] is encountered the program will execute the 'update statement' in the for-loop (in this case [font="Courier New"]'i++'[/font]) and jump to the beginning of the loop. In effect, the code below the continue statement will be skipped. In your case, however, there [i]is[/i] no code below the continue statement which makes it redundant. Typically you use a continue statement when you do not want to process certain elements in a list/array:

[code]
for (int i = 0; i < s; i++)
{
if(Objects[i].paintMe==false)
continue;

PaintObject(Objects[i]);
}
[/code]

2.[code]
int n = nameBack.Length;

for (int i = 0; i < n; i++)
{
Console.Write(nameBack[nameBack.Length -i -1]);
}
[/code]
The idea of saving the length of the string at the beginning is to ensure you are always referencing the original length. Also, when you only have a single statement in your loop you don't need the curly brackets:

[code]
int n = nameBack.Length;

for (int i = 0; i < n; i++)
Console.Write(nameBack[n-i-1]); // notice that we are now using 'n' instead of 'nameBack.Length'
[/code]
.. or, if you want to be really hardcore:

[code]
int n = nameBack.Length-1;

for(;n>=0;n--)
Console.Write(nameBack[n]);
[/code]

Share this post


Link to post
Share on other sites
I knew there would be things i didnt need, but i was just glad that i did it! :)

I have now done all those tasks (but i was unsure about the basic database, here is what I got though).

It may be a little rough around the edges but it does the job:

[code]using System;
using System.IO;

class BasicProject1
{

static void Main()
{
string name, nameUp, nameBack, namePerson, nameNumber;
int n;


// Task One

Console.Write("Please enter your name: ");
name = Console.ReadLine();

nameUp = name.ToUpper();
nameBack = name;

Console.WriteLine("\nYour name in capitals is: " + nameUp);

// Task Two

int s = name.Length;

for (int i = 0; i < s; i++)
{
Console.Write(name[i]);
Console.ReadKey(true);
}

// Task Three

Console.Write("\n\nYour name backwards is: ");

int b = nameBack.Length;

for (int i = 0; i < b; i++)
Console.Write(nameBack[b - i - 1]);

// Task Four

do
{
Console.Write("\nEnter your Name: ");
namePerson = Console.ReadLine();
} while (namePerson == "");

do
{
Console.Write("\nEnter your Number: ");
nameNumber = Console.ReadLine();
n = nameNumber.Length;
} while (n != 11);

Console.WriteLine("\nThe phone number you entered is: " + nameNumber);

// Task Five

StreamWriter writer;
writer = new StreamWriter(namePerson + ".txt");
writer.WriteLine("Your Name is: " + namePerson);
writer.WriteLine("Your phone number is: " + nameNumber);
writer.Close();

Console.WriteLine("\nYour info has now been saved to a file.");

Console.ReadLine();
}
}[/code]

Share this post


Link to post
Share on other sites
Next, Have the program ask a question like "How is the weather today? [Good, Bad, Fair, The Sun Just Exploded]" and have the program respond in different ways based on one of those 4 conditions.

Ex)
How is the weather today?> Good
Im glad the weather is Good today.

How is the weather today?> Bad
Im sorry the weather is Bad today.

How is the weathe today?> The Sun Just Exploded
Oh my, well, it was nice knowing you.



Share this post


Link to post
Share on other sites
[quote name='Net Gnome' timestamp='1312389366' post='4844120']
Next, Have the program ask a question like "How is the weather today? [Good, Bad, Fair, The Sun Just Exploded]" and have the program respond in different ways based on one of those 4 conditions.

Ex)
How is the weather today?> Good
Im glad the weather is Good today.

How is the weather today?> Bad
Im sorry the weather is Bad today.

How is the weathe today?> The Sun Just Exploded
Oh my, well, it was nice knowing you.

[/quote]

Thanks :) Heres the code for that:
[code]using System;
using System.IO;

class BasicProject1
{

static void Main()
{
string name, nameUp, nameBack, namePerson, nameNumber;
int n;


// Task One

Console.Write("Please enter your name: ");
name = Console.ReadLine();

nameUp = name.ToUpper();
nameBack = name;

Console.WriteLine("\nYour name in capitals is: " + nameUp);

// Task Two

int s = name.Length;

for (int i = 0; i < s; i++)
{
Console.Write(name[i]);
Console.ReadKey(true);
}

// Task Three

Console.Write("\n\nYour name backwards is: ");

int b = nameBack.Length;

for (int i = 0; i < b; i++)
Console.Write(nameBack[b - i - 1]);

// Task Four

do
{
Console.Write("\nEnter your Name: ");
namePerson = Console.ReadLine();
} while (namePerson == "");

do
{
Console.Write("\nEnter your Number: ");
nameNumber = Console.ReadLine();
n = nameNumber.Length;
} while (n != 11);

Console.WriteLine("\nThe phone number you entered is: " + nameNumber);

// Task Five

StreamWriter writer;
writer = new StreamWriter(namePerson + ".txt");
writer.WriteLine("Your Name is: " + namePerson);
writer.WriteLine("Your phone number is: " + nameNumber);
writer.Close();

Console.WriteLine("\nYour info has now been saved to a file.");

// Extra Task

Console.WriteLine("\nHow is the weather today?");
Console.WriteLine("(g = Good, b = Bad, f = Fair, d = The Sun Has Just Exploded AKA Death)");
string weather = Console.ReadLine();

switch (weather)
{
case "g":
Console.WriteLine("I am glad the weather is Good today!");
break;

case "b":
Console.WriteLine("I am sorry the weather is Bad today");
break;

case "f":
Console.WriteLine("It could be worse!");
break;

case "d":
Console.WriteLine("Oh my, well it was nice knowing you.");
break;

default:
Console.WriteLine("Please enter a valid answer!");
break;
}

Console.ReadLine();
}
}[/code]

Share this post


Link to post
Share on other sites
Sign in to follow this