Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
problem with c#

 
Post new topic   Reply to topic Printable version
 View previous topic  Ani's Summer Programming Projects Post :: Post why do people say a real programmer us...  View next topic  
Author Message
hellzlaker
Registered Cap Buster
Popping men in the ass since Oct 2005


Gender: NEVER ENOUGH!
Joined: Oct 27 2005
Posts: 34
Offline

PostPosted: Sun Apr 20, 2008 7:17 pm   Post maybe stupid    Post subject: problem with c# Reply to topic Reply with quote

i decided to learn C# and i am write now writing this little APP
Code: Show/Hide
using System;

class wanked
{
    static void Main()
    {
        string choice;
        string[] names;
        int[] ages;

        do
        {
            Console.Clear();
            Console.WriteLine("\tMenu\n\nA - add a name\nB - add age for a name\nC - view data\nQ - Exit\n\n");
            Console.WriteLine("Enter your choice: ");
            choice = Console.ReadLine();

            switch (choice)
            {
                case "A":
                case "a":
                    {
                        int num;
                        string input;

                        Console.Clear();
                        Console.WriteLine("How many names would you like to add?: ");

                        input = Console.ReadLine();
                        num = Int32.Parse(input);

                        for (int x = 0; x < num; x++)
                        {
                            Console.Clear();
                            Console.WriteLine("Enter name for following IDs:\n");
                            Console.WriteLine("ID #{0}: ", x);
                            names[x] = Console.ReadLine();
                        }
                        Console.Clear();
                        Console.WriteLine("Enter name for following IDS:\n");
                        Console.WriteLine("ID #{0}: ", num);
                        names[num] = Console.ReadLine();


                    }
                    break;
                case "B":
                case "b":
                    break;
                case "C":
                case "c":
                    break;
                case "Q":
                case "q":
                    break;
                default:
                    Console.Clear();
                    Console.WriteLine("{0} is not a valid choice! Try again, press Enter Key to continue...",choice);
                    Console.ReadLine();
                    Console.Clear();
                    break;
            }

        } while (choice != "q" && choice != "Q");
    }
}


its doesnt compile saying this
Code: Show/Hide
Error   3   Use of unassigned local variable 'names'   C:\Documents and Settings\Owner\Local Settings\Application Data\Temporary Projects\as\CodeFile1.cs   37   29   as


i dont get it since i declared names in the begining and it only does it to names in for loop not the one outsite :S icon_confused.gif
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address MSN Messenger
tcsoccerman
Server Help Squatter


Age:33
Gender:Gender:Male
Joined: Jan 15 2007
Posts: 694
Location: Atlantis
Offline

PostPosted: Sun Apr 20, 2008 8:17 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

string[] names = new string[size];

you have to use the new statement for arrays. look it up.
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address
hellzlaker
Registered Cap Buster
Popping men in the ass since Oct 2005


Gender: NEVER ENOUGH!
Joined: Oct 27 2005
Posts: 34
Offline

PostPosted: Sun Apr 20, 2008 8:34 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

i have another question how to run commands from DOS like in C++ its "system("cmd.exe d mrs.exe");"

so how do you do it in C#?
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address MSN Messenger
BDwinsAlt
Agurus's Posse


Age:34
Gender:Gender:Male
Joined: Jun 16 2003
Posts: 1145
Location: Alabama
Offline

PostPosted: Sun Apr 20, 2008 8:42 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

I think there is probably a better forum for what you're doing since it isn't subspace related.
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
D1st0rt
Miss Directed Wannabe


Age:37
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Sun Apr 20, 2008 11:17 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

The first thing that jumped out at me is that you don't need to (and shouldn't) be using all of those \n's. You should either split it up and call WriteLine for each one (it will do it for you which is actually why it is called WriteLine instead of just Write) or use Environment.NewLine.

You're not doing any validation of the number input, check out the TryParse method.

Also, you can use String.ToUpper to half the number of cases in your switch.

Running external things is done with System.Diagnostics.Process.Start
_________________

Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Mon Apr 21, 2008 4:11 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

Also...
Code: Show/Hide
                        for (int x = 0; x < num; x++)
                        {
                            Console.Clear();
                            Console.WriteLine("Enter name for following IDs:\n");
                            Console.WriteLine("ID #{0}: ", x);
                            names[x] = Console.ReadLine();
                        }
                        // don't need these 4 lines:
                        Console.Clear();
                        Console.WriteLine("Enter name for following IDS:\n");
                        Console.WriteLine("ID #{0}: ", num);
                        names[num] = Console.ReadLine();

_________________
ss news
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Cheese
Wow Cheese is so helpful!


Joined: Mar 18 2007
Posts: 1017
Offline

PostPosted: Sat Apr 26, 2008 1:03 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

-deleted, was crap-
_________________
SSC Distension Owner
SSCU Trench Wars Developer
Back to top
View users profile Send private message Add User to Ignore List Visit posters website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Trash Talk All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 122 page(s) served in previous 5 minutes.

phpBB Created this page in 0.559199 seconds : 31 queries executed (87.8%): GZIP compression disabled