🔒 Closed Pls Help po. c# application that counts positive and negative numbers.

Status
Not open for further replies.

ja_mario14

Fanatic
Paano ko po mapapadisplay ng ganito yung output, naattach po yung image ng result ng code ko tyka po
yung correct output ng application program sa ibaba. sana po matulungan niyo po ako.

============================================
using System;

class Program
{
static void Main() {

int i, sumPositive=0, sumNegative=0, countPositive=0, countNegative=0;
int[] arr = new int[10];

for(i=0;i<10;i++)
{
Console.Write("Enter Number: ");
arr = Convert.ToInt32(Console.ReadLine());
}

Console.Write("\nThe following are the numbers you entered:"+"\n\n");
for(i=0;i<10;i++)
{
Console.Write("{0} ", arr);
if(arr>0)
{
countPositive++;
sumPositive++;
}

if(arr<0)
{
countNegative++;
sumNegative++;
}

}
Console.Write("\n\nPositive Numbers: "+countPositive);
Console.Write("\nTotal Positive Numbers: "+sumPositive);

Console.Write("\n\nNegative Numbers: "+countNegative);
Console.Write("\nTotal Negative Numbers: "+sumNegative);
}
}

====================================================

PS. pasensya na po, di ko po mailagay yung code sa proper code text kasi wala po akong button.


Thank you in advance po mga master. God bless.


Correct Output.webp My Code Result.webp
 
Solution
Code:
using System;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main()
        {

            int i, sumPositive = 0, sumNegative = 0;
            int[] arr = new int[10], countPositive = new int[10], countNegative = new int[10];

            for (i = 0; i < 10; i++)
            {
                Console.Write("Enter Number: ");
                arr[i] = Convert.ToInt32(Console.ReadLine());
            }

            Console.Write("\nThe following are the numbers you entered:" + "\n\n");
            for (i = 0; i < 10; i++)
            {
                Console.Write(String.Format("{0} ", arr[i]));
                if (arr[i] > 0)
                {
                    countPositive[i] = arr[i]...
C#:
class Program
    {
        static void Main()
        {

            int i, sumPositive = 0, sumNegative = 0;
            int[] arr = new int[10];
            int[] countPositive = new int[10], countNegative = new int[10];

            for (i = 0; i < 10; i++)
            {
                Console.Write("Enter Number: ");
                arr[i] = Convert.ToInt32(Console.ReadLine());
            }

            Console.Write("\nThe following are the numbers you entered:" + "\n\n");
            for (i = 0; i < 10; i++)
            {
                Console.Write(String.Format("{0} ", arr[i]));
                if (arr[i] > 0)
                {
                    countPositive[i]= arr[i];
                    sumPositive++;
                }

                if (arr[i] < 0)
                {
                    countNegative[i]=arr[i];
                    sumNegative++;
                }

            }

                Console.Write("\n\nPositive Numbers: ");
            for (i = 0; i < 10; i++)
            {
                if (countPositive[i] > 0)
                {
                    Console.Write(String.Format("{0} ", countPositive[i]));
                }
            }

                Console.Write("\nTotal Positive Numbers: " + sumPositive);

            Console.Write("\n\nNegative Numbers: ");
            for (i = 0; i < 10; i++)
            {
                if (countNegative[i] != 0)
                {
                    Console.Write(String.Format("{0} ", countNegative[i]));
                }
            }

            Console.Write("\nTotal Negative Numbers: " + sumNegative);
            Console.ReadKey();
        }
    }
 
Hi sir. may error po sya.
pede pahelp po.?

C#:
class Program
    {
        static void Main()
        {

            int i, sumPositive = 0, sumNegative = 0;
            int[] arr = new int[10];
            int[] countPositive = new int[10], countNegative = new int[10];

            for (i = 0; i < 10; i++)
            {
                Console.Write("Enter Number: ");
                arr[i] = Convert.ToInt32(Console.ReadLine());
            }

            Console.Write("\nThe following are the numbers you entered:" + "\n\n");
            for (i = 0; i < 10; i++)
            {
                Console.Write(String.Format("{0} ", arr[i]));
                if (arr[i] > 0)
                {
                    countPositive[i]= arr[i];
                    sumPositive++;
                }

                if (arr[i] < 0)
                {
                    countNegative[i]=arr[i];
                    sumNegative++;
                }

            }

                Console.Write("\n\nPositive Numbers: ");
            for (i = 0; i < 10; i++)
            {
                if (countPositive[i] > 0)
                {
                    Console.Write(String.Format("{0} ", countPositive[i]));
                }
            }

                Console.Write("\nTotal Positive Numbers: " + sumPositive);

            Console.Write("\n\nNegative Numbers: ");
            for (i = 0; i < 10; i++)
            {
                if (countNegative[i] != 0)
                {
                    Console.Write(String.Format("{0} ", countNegative[i]));
                }
            }

            Console.Write("\nTotal Negative Numbers: " + sumNegative);
            Console.ReadKey();
        }
    }


sir may error po sya. pede pahel po
 
using System;

namespace ConsoleApplication2
{
class Program
{
static void Main()
{

int i, sumPositive = 0, sumNegative = 0;
int[] arr = new int[10], countPositive = new int[10], countNegative = new int[10];

for (i = 0; i < 10; i++)
{
Console.Write("Enter Number: ");
arr = Convert.ToInt32(Console.ReadLine());
}

Console.Write("\nThe following are the numbers you entered:" + "\n\n");
for (i = 0; i < 10; i++)
{
Console.Write(String.Format("{0} ", arr));
if (arr > 0)
{
countPositive = arr;
sumPositive++;
}

if (arr < 0)
{
countNegative = arr;
sumNegative++;
}

}

Console.Write("\n\nPositive Numbers: ");
for (i = 0; i < 10; i++)
{
if (countPositive > 0)
{
Console.Write(String.Format("{0} ", countPositive));
}
}

Console.Write("\nTotal Positive Numbers: " + sumPositive);

Console.Write("\n\nNegative Numbers: ");
for (i = 0; i < 10; i++)
{
if (countNegative != 0)
{
Console.Write(String.Format("{0} ", countNegative));
}
}

Console.Write("\nTotal Negative Numbers: " + sumNegative);
Console.ReadKey();
}
}
}
 
using System;

namespace ConsoleApplication2
{
class Program
{
static void Main()
{

int i, sumPositive = 0, sumNegative = 0;
int[] arr = new int[10], countPositive = new int[10], countNegative = new int[10];

for (i = 0; i < 10; i++)
{
Console.Write("Enter Number: ");
arr = Convert.ToInt32(Console.ReadLine());
}

Console.Write("\nThe following are the numbers you entered:" + "\n\n");
for (i = 0; i < 10; i++)
{
Console.Write(String.Format("{0} ", arr));
if (arr > 0)
{
countPositive = arr;
sumPositive++;
}

if (arr < 0)
{
countNegative = arr;
sumNegative++;
}

}

Console.Write("\n\nPositive Numbers: ");
for (i = 0; i < 10; i++)
{
if (countPositive > 0)
{
Console.Write(String.Format("{0} ", countPositive));
}
}

Console.Write("\nTotal Positive Numbers: " + sumPositive);

Console.Write("\n\nNegative Numbers: ");
for (i = 0; i < 10; i++)
{
if (countNegative != 0)
{
Console.Write(String.Format("{0} ", countNegative));
}
}

Console.Write("\nTotal Negative Numbers: " + sumNegative);
Console.ReadKey();
}
}
}



Sir meron pa rin po. gumagana po sainyo sir?
ndi po sakin.

ss.webp
 
mukhang nakuha ko kung bakit
nawala yung square brackets dun sa ibang variables

using System;

namespace ConsoleApplication2
{
class Program
{
static void Main()
{

int i, sumPositive = 0, sumNegative = 0;
int[] arr = new int[10], countPositive = new int[10], countNegative = new int[10];

for (i = 0; i < 10; i++)
{
Console.Write("Enter Number: ");
arr = Convert.ToInt32(Console.ReadLine());
}

Console.Write("\nThe following are the numbers you entered:" + "\n\n");
for (i = 0; i < 10; i++)
{
Console.Write(String.Format("{0} ", arr));
if (arr > 0)
{
countPositive = arr;
sumPositive++;
}

if (arr < 0)
{
countNegative = arr;
sumNegative++;
}

}

Console.Write("\n\nPositive Numbers: ");
for (i = 0; i < 10; i++)
{
if (countPositive > 0)
{
Console.Write(String.Format("{0} ", countPositive));
}
}

Console.Write("\nTotal Positive Numbers: " + sumPositive);

Console.Write("\n\nNegative Numbers: ");
for (i = 0; i < 10; i++)
{
if (countNegative != 0)
{
Console.Write(String.Format("{0} ", countNegative));
}
}

Console.Write("\nTotal Negative Numbers: " + sumNegative);
Console.ReadKey();
}
}
}


Mukhang naaalis yung square brackets kapag nai paste ko na dito. Try ko mag attach ng text file.

Paki try itong nasa text file

why2.webp
 

Attachments

mukhang nakuha ko kung bakit
nawala yung square brackets dun sa ibang variables

using System;

namespace ConsoleApplication2
{
class Program
{
static void Main()
{

int i, sumPositive = 0, sumNegative = 0;
int[] arr = new int[10], countPositive = new int[10], countNegative = new int[10];

for (i = 0; i < 10; i++)
{
Console.Write("Enter Number: ");
arr = Convert.ToInt32(Console.ReadLine());
}

Console.Write("\nThe following are the numbers you entered:" + "\n\n");
for (i = 0; i < 10; i++)
{
Console.Write(String.Format("{0} ", arr));
if (arr > 0)
{
countPositive = arr;
sumPositive++;
}

if (arr < 0)
{
countNegative = arr;
sumNegative++;
}

}

Console.Write("\n\nPositive Numbers: ");
for (i = 0; i < 10; i++)
{
if (countPositive > 0)
{
Console.Write(String.Format("{0} ", countPositive));
}
}

Console.Write("\nTotal Positive Numbers: " + sumPositive);

Console.Write("\n\nNegative Numbers: ");
for (i = 0; i < 10; i++)
{
if (countNegative != 0)
{
Console.Write(String.Format("{0} ", countNegative));
}
}

Console.Write("\nTotal Negative Numbers: " + sumNegative);
Console.ReadKey();
}
}
}


Mukhang naaalis yung square brackets kapag nai paste ko na dito. Try ko mag attach ng text file.

Paki try itong nasa text file


try ko po sir.
pasensya na po sir. salamat po.
 
Code:
using System;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main()
        {

            int i, sumPositive = 0, sumNegative = 0;
            int[] arr = new int[10], countPositive = new int[10], countNegative = new int[10];

            for (i = 0; i < 10; i++)
            {
                Console.Write("Enter Number: ");
                arr[i] = Convert.ToInt32(Console.ReadLine());
            }

            Console.Write("\nThe following are the numbers you entered:" + "\n\n");
            for (i = 0; i < 10; i++)
            {
                Console.Write(String.Format("{0} ", arr[i]));
                if (arr[i] > 0)
                {
                    countPositive[i] = arr[i];
                    sumPositive++;
                }

                if (arr[i] < 0)
                {
                    countNegative[i] = arr[i];
                    sumNegative++;
                }

            }

            Console.Write("\n\nPositive Numbers: ");
            for (i = 0; i < 10; i++)
            {
                if (countPositive[i] > 0)
                {
                    Console.Write(String.Format("{0} ", countPositive[i]));
                }
            }

            Console.Write("\nTotal Positive Numbers: " + sumPositive);

            Console.Write("\n\nNegative Numbers: ");
            for (i = 0; i < 10; i++)
            {
                if (countNegative[i] != 0)
                {
                    Console.Write(String.Format("{0} ", countNegative[i]));
                }
            }

            Console.Write("\nTotal Negative Numbers: " + sumNegative);
            Console.ReadKey();
        }
    }
}
 
Solution
Status
Not open for further replies.

About this Thread

  • 10
    Replies
  • 798
    Views
  • 2
    Participants
Last reply from:
ja_mario14

Online now

Members online
1,000
Guests online
1,379
Total visitors
2,379

Forum statistics

Threads
2,276,208
Posts
28,968,320
Members
1,231,166
Latest member
williamfreede
Back
Top