• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

PLS HELP why is this wrong

Question

anonymouses    0

im trying to make a pizza order but why doesnt the result have decimals even though it is double

 


using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace PizzaChat
{
    /// <summary>
    /// Description of MainForm.
    /// </summary>
    public partial class MainForm : Form
    {
        public MainForm()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();
            
            //
            // TODO: Add constructor code after the InitializeComponent() call.
            //
        }
            
        void OrdbtClick(object sender, EventArgs e)
        {
            double amount, amountqua;
            int quantity = int.Parse(quantb.Text);
            double crust1 = 0.00;
            double size = 0.00;
            double cheese = 12.75, anchovies = 18.50, ham = 40.90, veg = 50.75, pineapple = 75.50, pepperoni = 45.50;
            double toppings;
            double toppings1 = 0.00,toppings2 = 0.00,toppings3 = 0.00,toppings4 = 0.00,toppings5 = 0.00,toppings6 = 0.00;
            
            if (thkrdbt.Checked)
            {
                if(panrdbt.Checked)
                {
                    crust1 = 150.75;
                    size = 100.00;
                }
                
                else if (regrdbt.Checked)
                {
                    crust1 = 150.75;
                    size = 200.00;
                }
                else if (parrdbt.Checked)
                {
                    crust1 = 150.75;
                    size = 400.00;
                }
                
            }
            else if (thinrdbt.Checked)
            {
                if(panrdbt.Checked)
                {
                    crust1 = 275.50;
                    size = 100.00;
                }
                
                else if (regrdbt.Checked)
                {
                    crust1 = 275.50;
                    size = 200.00;
                }
                else if (parrdbt.Checked)
                {
                    crust1 = 275.50;
                    size = 400.00;
                }
            }
            
            else
            {
                MessageBox.Show("ERROR","ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
                
        
            
            {
            if (chechkbx.Checked)
            {
                toppings1 = cheese;
            }
            if (anchkbx.Checked)
            {
                toppings2 = anchovies;
            }
            if (hmchkbx.Checked)
            {
                toppings3 = ham;
            }
            if (vegchkbx.Checked)
            {
                toppings4 = veg;
            }
            if (pnpchkbx.Checked)
            {
                toppings5 = pineapple;
            }
            if (peppechkbx.Checked)
            {
                toppings6 = pepperoni;
            }
            }
            toppings = toppings1 + toppings2 + toppings3 + toppings4 +toppings5 + toppings6;
        
            amount = crust1 + size + toppings;
            amountqua = quantity * amount;
            lblamount.Text = amount.ToString(lblamount.Text + " PHP");
            
    
    }
        void ExbtClick(object sender, EventArgs e)
        {
            Application.Exit();
        }
        void MainFormLoad(object sender, EventArgs e)
        {
    
        }
}
}

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0
+forster    153

3q17qe.thumb.jpg.30ca93d9e7babafb608de17b2d6d4cd2.jpg

Share this post


Link to post
Share on other sites
  • 0
adrynalyne    13,021

Your code is chaotic, so I am going to assume you are a student and this is homework. Therefore I will not give you a precise answer.

 

I glanced over it, and I'd say the problem is likely here.

 

lblamount.Text = amount.ToString(lblamount.Text + " PHP");

 

 

https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings

Edited by adrynalyne

Share this post


Link to post
Share on other sites
  • 0
neufuse    4,110
1 hour ago, adrynalyne said:

Your code is chaotic, so I am going to assume you are a student and this is homework. Therefore I will not give you a precise answer.

 

I glanced over it, and I'd say the problem is likely here.

 


lblamount.Text = amount.ToString(lblamount.Text + " PHP");

 

 

https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings

yeah..... that ain't no format string there being passed in...

 

if you need a hint...... amount.ToString("F") // Fixed point two digit format

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.