7 Replies - 549 Views - Last Post: 04 November 2011 - 07:10 AM Rate Topic: -----

#1 matanl1234  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 01-November 11

how to define as many as numbers? (console)

Posted 03 November 2011 - 02:18 PM

i wrote the next code:

 static int DiffNumbers (int num)
    {
        int numCounter=0;
        if (num==0)
        {
            numCounter = 1;
        }
        while (num>0)
        {
            num = num / 10;
            numCounter++;
        }


how do i define "numCounter" ammount of numbers as int?
Is This A Good Question/Topic? 0
  • +

Replies To: how to define as many as numbers? (console)

#2 Tryparse  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 80
  • View blog
  • Posts: 193
  • Joined: 20-April 10

Re: how to define as many as numbers? (console)

Posted 03 November 2011 - 02:42 PM

Are you trying to dynamically create variables (ints) at runtime? If so, your best bet is going to be to use an array or list.
int[] numberArray = new int[numCounter];
//or
List<int> numberList = new List<int>(numCounter);

Was This Post Helpful? 0
  • +
  • -

#3 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • Posts: 3,002
  • Joined: 30-January 11

Re: how to define as many as numbers? (console)

Posted 03 November 2011 - 02:43 PM

I don't really understand your question. The numCounter variable is already of type int. Perhaps try modifying your question slightly?
Was This Post Helpful? 0
  • +
  • -

#4 matanl1234  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 01-November 11

Re: how to define as many as numbers? (console)

Posted 03 November 2011 - 02:47 PM

how do i use the array or list later?
Was This Post Helpful? 0
  • +
  • -

#5 Tryparse  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 80
  • View blog
  • Posts: 193
  • Joined: 20-April 10

Re: how to define as many as numbers? (console)

Posted 03 November 2011 - 03:36 PM

You can iterate through the array/list using a for or foreach loop, or you can access them via their indices.
Was This Post Helpful? 0
  • +
  • -

#6 matanl1234  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 01-November 11

Re: how to define as many as numbers? (console)

Posted 04 November 2011 - 03:54 AM

how can i compare them to each other?

one of the list to all other of the list,
or one of the arrat to all other?
Was This Post Helpful? 0
  • +
  • -

#7 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4468
  • View blog
  • Posts: 7,780
  • Joined: 08-June 10

Re: how to define as many as numbers? (console)

Posted 04 November 2011 - 06:17 AM

Your questions are too vague, and you haven't provided any attempted code implementing anything that has been suggested.

We can't help you this way. You must be much more specific in what you are asking, because frankly, I have absolutely no clue what you want.
Was This Post Helpful? 0
  • +
  • -

#8 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5480
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: how to define as many as numbers? (console)

Posted 04 November 2011 - 07:10 AM

Quote

I have a little C# experience but I need to write ...


You need to start there. I can't say "I have little experience in speaking Russian, but I have been assigned to write a mystery novel in Russian. Can you help me?"

We can help you by saying "First learn basic programming and the language of C#. Then take on assignments." Could someone here write this program for you? Sure. Could someone here map out all the processes you need to follow and do the Software Design part of this in the slim hope you could code it from there? Sure. But we don't volunteer to do the job that you're either getting paid for, or getting a grade for. You may want to read this.

For now, just work on the lessons. Do a self-teaching book from cover to cover. Then consider writing a program.

Don't try to create a useful working program to fit a need of yours (or a for-pay contract) as your introduction to coding project. When you are learning to code you don't know enough to code a program, let alone know how to engineer the architecture of a program. It would be like saying "I don't know how to read sheet music, or play an instrument. I think I'll write a 3 act opera as my first learning experience."

I don't say this to be mean. We've seen lots of new coders take this approach and we know it doesn't work. Trying to design your own programs before you understand the basics of the code language you've chosen just leads to problems, frustrations, and 'swiss-cheese' education (lots of holes).


Resources, references and suggestions for new programmers. - Updated Oct 2011
Spoiler

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1