CFanatic

Go Back   CFanatic > Programming > C# Programming

Join CFanatic Forum Now

c# for loop topic posted under C# Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 09-06-2010, 01:43 AM
Junior Member
 
Join Date: Sep 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
jigglymig1 is on a distinguished road
| More
c# for loop

i'm new to c# so i don't know how to use a for loop to increment my nums. num[i] 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;
            }
        }
    }
}
Reply With Quote
  #2  
Old 09-06-2010, 03:28 AM
coderzone's Avatar
Senior Member
 
Join Date: May 2007
Posts: 273
Thanks: 16
Thanked 12 Times in 12 Posts
coderzone is on a distinguished road
| More
Re: c# for loop

num[i] works if you declare them as array and above code will not work in any programming language I suppose.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
while loop help nate201 C Programming 0 09-03-2010 03:52 PM
What is loop techinspiration C Programming 3 08-07-2010 06:11 AM
loop program s.kavita C++ Programming 1 07-25-2010 08:35 AM
Loop problem creative C Programming 6 04-02-2010 09:17 PM
Do While loop syntax codeunlock C# Programming 1 04-29-2007 08:31 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 03:34 PM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board