我试图创建一个计算器程序,但在除法方法中,我需要返回 2 个值,它们是默认参数中的余数和 out 参数中的商我尽了最大努力,但我无法正确得到答案
using System;
public class Calculator
{
public int Addition(int a, int b){
int sum = a+b;
return sum;
}
public int Subtraction(int a, int b){
int diff = a-b;
return diff;
}
public int Multiplication(int a, int b){
int mul = a*b;
return mul;
}
public double Division(int a, int b, out double remainder){
double div = a/b;
double rem = a%b;
remainder = rem;
return div;
}
}
public class program{
public static void Main(){
Calculator c = new Calculator();
Console.WriteLine("Enter the operator");
char s=Convert.ToChar(Console.ReadLine());
Console.WriteLine("Enter the operands");
int a=Convert.ToInt32(Console.ReadLine());
int b=Convert.ToInt32(Console.ReadLine());
switch(s)
{
case '+':
int summ = c.Addition(a,b);
Console.WriteLine("Result of {0} + {1} is {2}",a,b,summ);
break;
case '-':
int sub = c.Subtraction(a,b);
Console.WriteLine("Result of {0} - {1} is {2}",a,b,sub);
break;
case'*':
int mul = c.Multiplication(a,b);
Console.WriteLine("Result of {0} * {1} is {2}",a,b,mul);
break;
case '/':
double div = c.Division(a,b,out a);
Console.WriteLine("Result of {0} / {1} is {2} and rem is {3}",a,b,div,a);
break;
default:
Console.WriteLine("Invalid Operand");
break;
}
}
}
幕布斯6054654
达令说
RISEBY
相关分类