查看: 783|回复: 1
|
Why can't display desire result?(c#)
[复制链接]
|
|
为何我的 total 一直 是 0
using System;
class Calculate
{
private int casesSold;
private int soldBar;
private double pricePerBar;
private double afterDiscoundPerBar;
private double total;
public Calculate(int cases,double price)
{
casesSold = cases;
pricePerBar = price;
SetCasesSold(cases);
SetEarn(price);
SetTotal();
}
public void SetCasesSold(int val)
{
soldBar=val*12;
}
public void SetEarn(double val)
{
afterDiscoundPerBar = val * ((100 - 10) / 100);
}
public void SetTotal()
{
total= afterDiscoundPerBar* soldBar;
}
public int GetSoldBar()
{
return soldBar;
}
public double GetEarn()
{
return afterDiscoundPerBar;
}
public double GetTotal()
{
return total;
}
}
class Price
{
public static void Main()
{
Console.WriteLine("How many cases sold?");
int cases = int.Parse(Console.ReadLine());
Console.WriteLine("Price Per bar sold :");
double perBar = double.Parse(Console.ReadLine());
Calculate First = new Calculate(cases,perBar);
Console.WriteLine("Total is :" + First.GetTotal());
Console.ReadLine();
}
} |
|
|
|
|
|
|
|
发表于 21-3-2006 08:41 AM
|
显示全部楼层
public void SetEarn(double val)
{
afterDiscoundPerBar = val * ((100 - 10) / 100);
//((100 - 10) / 100); is always 0
}
怀疑converted to int了 。 。
试把它convert 去double 吧 。 。
[ 本帖最后由 backspace 于 21-3-2006 08:47 AM 编辑 ] |
|
|
|
|
|
|
| |
本周最热论坛帖子
|