Answer to Question #20985 in C# for ally

Question #20985
Visual C# or C# IDE

Program that will ask the user to input a number, program will determine and display if the input is odd or even and it will also display all the sum of all even and numbers from the given input.

here's my code so far..

int sum = 0;


for (int i = 0; i <= input; i++)
{
if (i % 2 == 0)
{
sum += i;
lblAllEven.Text = sum.ToString();
lblOutput.Text = "EVEN";
}
else
{
lblAllOdd.Text = sum.ToString();
lblOutput.Text = "ODD";
}
}

please help me fix my code..
1
Expert's answer
2012-12-21T05:51:44-0500
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
& private int Sum{get;set;}
& private int Number{get;set;}
& public Form1()
& {
InitializeComponent();
& }

& private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
& {
}

& private void textBox1_KeyDown(object sender, KeyEventArgs e)
& {

if (e.KeyValue==13)
{
try
{
& Number = Convert.ToInt32(TBNumber.Text);
}
catch
{
& Number = 0;
}

Sum += Number;
if (Number%2==0)
{
& lPair.Text=&quot;It's pair&quot;;
}
else
{
& lPair.Text=&quot;It's not pair&quot;;
}

lSum.Text=Sum.ToString();

}
& }
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS