控制台应用,C# 收据程序

本文关键字:程序 应用 控制台 | 更新日期: 2023-09-27 18:33:32

我是 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();

它必须看起来像这样,我完成了格式,但我在上述问题方面遇到了问题,请帮助

程序图片

控制台应用,C# 收据程序

使用整数 32 的十进制 instad。

       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();