我是c#的新手,我正在尝试打印收据,但我的代码无效。这是我的问题:
计算价格乘以用户提供的数量
计算上述金额 - 12%税收显示增值税接受款项
计算一旦输入单价后所有出现的变化
这是我目前的计算部分代码
bool test = false;
do
{
try
{
Console.SetCursorPosition(2, 12);
Console.Write(" ");
Console.SetCursorPosition(2, 12);
Num = Convert.ToInt32(Console.ReadLine());
test = false;
}
catch
{
test = true;
}
} while (test);
Console.SetCursorPosition(18, 12);
Console.ForegroundColor = ConsoleColor.Yellow;
telNumber = Console.ReadLine();
//Peso
bool Ptest = false;
do
{
try
{
Console.SetCursorPosition(47, 12);
Console.Write(" ");
Console.SetCursorPosition(47, 12);
Amount = Convert.ToInt32(Console.ReadLine());
Console.SetCursorPosition(65, 12);
Amount = Amount * 2 ;
Console.WriteLine("P " + Amount.ToString("0.00"));
Console.SetCursorPosition(65, 15);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("P " + Amount.ToString("0.00"));
Console.SetCursorPosition(65, 17);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("P " + Amount.ToString("0.00"));
Ptest = false;
}
catch
{
Ptest = true;
}
} while (Ptest);
//Amount
Console.ReadLine();
它必须看起来像这样,我已完成格式但我遇到上述问题时遇到问题,请帮忙
答案 0 :(得分:0)
使用小数而不是整数32.
bool test = false;
do
{
try
{
Console.SetCursorPosition(2, 12);
Console.Write(" ");
Console.SetCursorPosition(2, 12);
Num = Convert.ToDecimal(Console.ReadLine());
test = false;
}
catch
{
test = true;
}
} while (test);
Console.SetCursorPosition(18, 12);
Console.ForegroundColor = ConsoleColor.Yellow;
telNumber = Console.ReadLine();
bool Ptest = false;
do
{
try
{
Console.SetCursorPosition(47, 12);
Console.Write(" ");
Console.SetCursorPosition(47, 12);
Amount = Convert.ToDecimal(Console.ReadLine());
Console.SetCursorPosition(65, 12);
Amount = Amount * 2;
Console.WriteLine("P " + Amount.ToString("0.00"));
Console.SetCursorPosition(65, 15);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("P " + Amount.ToString("0.00"));
Console.SetCursorPosition(65, 17);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("P " + Amount.ToString("0.00"));
Ptest = false;
}
catch
{
Ptest = true;
}
} while (Ptest);
//Amount
Console.ReadLine();