1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

c# for loop

Discussion in 'C#' started by jigglymig1, Sep 6, 2010.

  1. jigglymig1

    jigglymig1 New Member

    Joined:
    Sep 6, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    i'm new to c# so i don't know how to use a for loop to increment my nums. num apparently doesn't work in c#
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                int num1;
                int num2;
                int num3;
                int num4;
                int num5;
                int neg = 0;
                int zero = 0;
                int pos = 0;
                int i;
                Console.WriteLine("enter 5 numbers");
                num1 = Convert.ToInt32(Console.ReadLine());
                num2 = Convert.ToInt32(Console.ReadLine());
                num3 = Convert.ToInt32(Console.ReadLine());
                num4 = Convert.ToInt32(Console.ReadLine());
                num5 = Convert.ToInt32(Console.ReadLine());
                for (i=1; i < 6; i++)
                {
                    if (num[i] < 0)
                        neg = neg + 1;
                    if (num[i] == 0)
                        zero = zero + 1;
                    if (num[i] > 0)
                        pos = pos + 1;
                }
            }
        }
    }
     
  2. go4expert

    go4expert Moderator

    Joined:
    Aug 3, 2004
    Messages:
    306
    Likes Received:
    7
    Trophy Points:
    0
    num works if you declare them as array and above code will not work in any programming language I suppose.
     

Share This Page