C#中的循环和条件

时间:2015-06-09 12:48:58

标签: loops

C#非常新,还在学习。这是一个循环和条件我想创建:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyLoop
{
    class Program
    {
        static void Main(string[] args)
        {

            int LineA = 4;
            int LineB = 200;
            int LineC = 10;
            int LineD = 3600;
            int X;
            int Y;

            //X is equals to: Add LineA number to the LineD number
            //Y is equals to:  Add LineB number to the LineC number
            //Condition:
            //Is X is greater  than Y? 
            //Answer: No then
            //Is X is equal to Y?
            //Answer: No then
            //Keep lopping until it matches to the Y and then stop.
            //So what will be final number/value for both X and Y?


        }
    }
}

如何输入C#代码?

有人可以帮我开始吗?我真的很困惑从哪里开始..

1 个答案:

答案 0 :(得分:1)

我还是初学者,但您可以将其作为代码的基础。问题是X大于Y,因此应该是输出结果。

 int LineA, LineB, LineC, LineD;
        LineA = 4;
        LineB = 200;
        LineC = 10;
        LineD = 3600;

        int X;
        int Y;

        X = LineA + LineD;
        Y = LineB + LineC;

        if (X > Y)
            Console.WriteLine("X is greater than y");
        else if(X==Y)
            Console.WriteLine("X is equal to y");
        else
        {
            Console.WriteLine("Something");
        }

        Console.ReadLine();