🔒 Closed Please Help me

Status
Not open for further replies.

ja_mario14

Fanatic
using System;

class program
{
static void Main()
{
int i, num, sum=0, total=0;


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

if(num%2==0)
{

sum+=num;
}
}
Console.Write("\n\nSum of Number Divisible By 2: {0} \n",sum);

if(num%2==0)
{
total = num+i;
}
Console.WriteLine("Total Number Divisible By 2: {0} \n",total);
}
}


Here is the question problem.

1.webp
 
Use descriptive variable names, avoid using i, j, k, etc...

1649143114031.png


C#:
using System;

class program
{
   
    static void Main()
    {
        const int DIVISIBLE_BY = 2;
        int numberInput, sumOfNumbers = 0, totalNumbers = 0;

        for (int currentNumber = 1; currentNumber <= 10; currentNumber++)
        {
            Console.Write($"Enter Number {currentNumber}: ");
            numberInput = Convert.ToInt32(Console.ReadLine());

            if (numberInput % DIVISIBLE_BY == 0)
            {
                sumOfNumbers += numberInput;
                totalNumbers++;
            }
        }
        Console.WriteLine("Sum of Number Divisible By 2: {0} \n", sumOfNumbers);
        Console.WriteLine("Total Number Divisible By 2: {0} \n", totalNumbers);
    }
}

Please use the code functionality when posting codes:

1649143189877.webp
 
Use descriptive variable names, avoid using i, j, k, etc...

View attachment 1885736

C#:
using System;

class program
{
  
    static void Main()
    {
        const int DIVISIBLE_BY = 2;
        int numberInput, sumOfNumbers = 0, totalNumbers = 0;

        for (int currentNumber = 1; currentNumber <= 10; currentNumber++)
        {
            Console.Write($"Enter Number {currentNumber}: ");
            numberInput = Convert.ToInt32(Console.ReadLine());

            if (numberInput % DIVISIBLE_BY == 0)
            {
                sumOfNumbers += numberInput;
                totalNumbers++;
            }
        }
        Console.WriteLine("Sum of Number Divisible By 2: {0} \n", sumOfNumbers);
        Console.WriteLine("Total Number Divisible By 2: {0} \n", totalNumbers);
    }
}

Please use the code functionality when posting codes:

View attachment 1885738
Noted po sir. Sorry po newbie palang po. thank you po sir.
 
Status
Not open for further replies.

About this Thread

  • 2
    Replies
  • 405
    Views
  • 2
    Participants
Last reply from:
ja_mario14

Online now

Members online
970
Guests online
1,195
Total visitors
2,165

Forum statistics

Threads
2,276,186
Posts
28,968,141
Members
1,231,156
Latest member
zaiyee777
Back
Top