问题描述:

I'm new in c# and I'm trying to print a receipt, but my code is not working. Here is my problem:

  • Compute the Price multiplied by the quantity given by the user

  • Compute the said Amount - 12% tax Show the Vat Tax Accept money and

  • compute the change they have to all appear once the unit price has been inputted

This is my code at the moment for the computation part

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

It has to look like this, Ive done the format but I'm having trouble with the said problems above, please help

Program Image

网友答案:

Use decimal instad of integer 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();
相关阅读:
Top