C# 基本计算器锐化显黑错误

本文关键字:错误 锐化 计算器 | 更新日期: 2023-09-27 18:31:47

我的目标是创建一个简单的代码,它接受输入并给出数字的平方。我使用了另一种计算方法,但我认为方法设置有错误。请看一看。

using System;
namespace NumberM {
    class InputLocation {
        public static void Main (string [] args) {
            int PlsCall;
        begin:
            Console.Write ("Please specify a number : ");
            string NumInput = Console.ReadLine ();
            int NumNewValue = Int32.Parse (NumInput);
            Console.WriteLine("Is {0} the number you specified?", NumNewValue);
            string Ans = Console.ReadLine();
            if (Ans == "yes" || Ans == "Yes") {
                Console.WriteLine ("That means {0} is your number. All right. Calculating.");
                // disable once SuggestUseVarKeywordEvident
                CalcNumb InP = new CalcNumb();
                PlsCall = InP.Calculation (NumNewValue);
            } else {
                 Console.WriteLine ("That might be an issue. Taking back.");
                 goto begin;
            }
        }
    }
    class CalcNumb {
        public int Calculation (int number) {
            int Store = number * number;
            Console.WriteLine ("This is the square of your number : {0}" , Store);
            }
    }
}

我在调用方法的第 35 行和第 26 行收到错误。 PlsCall = InP.Computing (NumNewValue); 公共 int 计算(int 编号)

{

我得到这样的东西。我翻译不好,但如果你需要翻译,它是土耳其语。

'NumberM.CalcNumb.Computing(int)': tüm kod yolları değer döndürmez (CS0161)

提前感谢您的帮助。

C# 基本计算器锐化显黑错误

计算方法是一个整数,您不返回任何内容

  public int Calculation (int number) 
  {
     int Store = number * number;
     Console.WriteLine ("This is the square of your number : {0}" , Store);
     return Store; // Needed
  }

你的方法 计算不返回值

替换

class CalcNumb { public int Calculation (int number) { int Store = number * number; Console.WriteLine ("This is the square of your number : {0}" , Store); } }

class CalcNumb { public int Calculation (int number) { int Store = number * number; Console.WriteLine ("This is the square of your number : {0}" , Store); return Store; } }

你必须返回一些东西!

public int Calculation (int number) 
{
    int Store = number * number;
    Console.WriteLine ("This is the square of your number : {0}" , Store);
    return Store;
}

此行中的另一个错误:

Console.WriteLine ("That means {0} is your number. All right. Calculating.");

它应该是:

Console.WriteLine ("That means {0} is your number. All right. Calculating.", NumNewValue);

并且,请避免在 C# 代码;)中goto