3 回答
TA贡献1876条经验 获得超7个赞
双除提醒;//对于你的输出参数
计算器 c = new Calculator();
double divResult = c.Division(33/8,divisionRemider);
divResult 将为 4
devisionRemider 将是 1
TA贡献1821条经验 获得超6个赞
你在这里做错了
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;
你必须在 main 函数中声明新的变量来存储提醒 EX: int rem;
解决办法是:
case '/':
int rem;
double div = c.Division(a,b,out rem);
Console.WriteLine("Result of {0} / {1} is {2} and rem is {3}",a,b,div,rem);
break;
TA贡献1856条经验 获得超5个赞
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(){
double remainder;
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 remainder);
Console.WriteLine("Result of {0} / {1} is {2} and rem is {3}",a,b,div,remainder);
break;
default:
Console.WriteLine("Invalid Operand");
break;
}
}
}
- 3 回答
- 0 关注
- 200 浏览
添加回答
举报