Home > database >  how do i convert this code from console app to windows form app
how do i convert this code from console app to windows form app

Time:09-12

i have tried change it from settings to windows form but the app doesn't run this is the code

   [the code][1]

sample

 using System;
public class Exercise053
{
    public static void Main()
    {
        int price, paid, change;

        Console.Write("Price? ");
        price = Convert.ToInt32(Console.ReadLine());
        Console.Write("Paid? ");
        paid = Convert.ToInt32(Console.ReadLine());

        change = paid - price;
        Console.Write("Your change is {0}: ", change);
        while (change > 0)

CodePudding user response:

using System;
public class Exercise053
{
    public static void Main()
    {
        int price, paid, change;

        Console.Write("Price? ");
        price = Convert.ToInt32(Console.ReadLine());
        Console.Write("Paid? ");
        paid = Convert.ToInt32(Console.ReadLine());

        change = paid - price;
        Console.Write("Your change is {0}: ", change);
        while (change > 0)
        {
            if (change >= 50)
            {
                Console.Write("50 ");
                change -= 50;
            }
            else
            {
                if (change >= 20)
                {
                    Console.Write("20 ");
                    change -= 20;
                }
                else
                {
                    if (change >= 10)
                    {
                        Console.Write("10 ");
                        change -= 10;
                    }
                    else
                    {
                        if (change >= 5)
                        {
                            Console.Write("5 ");
                            change -= 5;
                        }
                        else
                        {
                            if (change >= 2)
                            {
                                Console.Write("2 ");
                                change -= 2;
                            }
                            else
                            {
                                Console.Write("1 ");
                                change -= 1;
                            }
                        }
                    }
                }
            }
        }
        Console.WriteLine();
    }
}

CodePudding user response:

I would suggest you use 2 labels, for the questions, then 2 textboxes for the inputs and below a button to confirm the inputs, then just display the results with the help of MessageBox-es instead of Console.Writeline(), and it would work. Some good resources for your app, that might help:

How to make a winforms app: Microsoft Documentation

How to work with textboxes: c-sharp corner on how to use TextBox component

How to work with messageboxes: c-sharp corner on how to work with MessageBox component

  •  Tags:  
  • c#
  • Related