我的号码程序问题c# [英] Problems with my number program c#

查看:80
本文介绍了我的号码程序问题c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我遇到以下代码的麻烦,并希望它返回一个数字的因素,但我有多个奇怪的错误

i am having troubel with the following code and would like it to return a number's factors but i am having multiplee weird errors

using System;

namespace Algorythm_test
{
	class Program
	{
		public static void Main(string[] args)
		{
			System.Console.WriteLine("Emersont1's Factor finder\n Please Enter your Number to check factors");
			int Lim = Convert.ToInt32(Console.Read());
				System.Console.WriteLine("The Number " + Lim + " has " + Factors(Lim) + " factors");
		}
 

 
			public int Factors(int value)
			{
    		int Secondnum = 1;
    		While Secondnum <=value;
    		{
    			if (value % Secondnum == 0)
       				{
          				Factors++;
       				}
       
      			Secondnum++;
    		}
         
    
    return Factors;
}
			
		}
	}

感谢您的支持

Emersont1

Emersont1

推荐答案

C#语法中有三个主要错误(参见下面的代码块)。你最近从VB那里迈出了一步吗?几年前我自己做到了。无论如何,试试这段代码:

There where three major errors in your C# syntax (see below code block). Did you recently take the step from VB? Did that myself a few years back. Anyway, try this code:

class Program
{
    static void Main(string[] args)
    {
        System.Console.WriteLine("Emersont1's Factor finder\n Please Enter your Number to check factors");
	int Lim = Convert.ToInt32(Console.Read());
	System.Console.WriteLine("The Number " + Lim + " has " + Factors(Lim) + " factors");
    }


    public static int Factors(int value)
    {
        int retval = 0;
        int Secondnum = 1;

        while (Secondnum <= value)
        {
            if (value % Secondnum == 0)
            {
                retval++;
            }

            Secondnum++;
        }

        return retval;
    }
}

1。您的因子方法需要在此控制台应用程序中声明为静态。

1. Your Factors method needs to be declared as static in this console application.

2。方法不能返回方法名称作为结果(比如在VB中),所以我为你创建了一个retval变量。

2. A method can't return the method name as the result (like in VB), so I've created the retval variable for you.

3。你拼写"while"用大写字母"w"。大禁忌,再次是VB。

3. You spelled "while" with a capital "w". Big no-no, that's VB again.

我没有为你检查逻辑,但现在你可以运行代码了。祝你好运!

I didn't check the logic for you, but now you can run the code. Good luck!

请记得"标记为答案"解决您问题的
回复。这是识别那些帮助过您的人的常用方法,并且让其他访问者更容易在以后找到解决方案。





这篇关于我的号码程序问题c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆