Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7042753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:12:23+00:00 2026-05-28T02:12:23+00:00

I am trying to make a small pizza order form, but I have a

  • 0

I am trying to make a small pizza order form, but I have a problem with the calculations. After selecting a pizza, the unit price and total calculations are OK but selecting additions introduces a problem. After changing the NumericUpDown value, the calories are not correct (all units have constant prices and calories). The NumericUpDown’s name is numberofunit. How can I calculate them?

if (pepper.Checked)
{
    string peppereklendi = 
        Convert.ToString(Convert.ToDouble(unitprice.Text)+ pepperprice);

    unitprice.Text = peppereklendi;

    total.Text = 
        Convert.ToString(Convert.ToDecimal(unitprice.Text) * numberofunit.Value);

    string pepperkaloriekle = 
        Convert.ToString(Convert.ToInt16(gizlikalori.Text) + pepperkalori);

    gizlikalori.Text = pepperkaloriekle;

    amountofcalorie.Text = 
        Convert.ToString(Convert.ToDecimal(gizlikalori.Text) * numberofunit.Value);
}
else
{
    string peppereklendi = unitprice.Text;

    unitprice.Text = 
        Convert.ToString(Convert.ToDouble(peppereklendi) - pepperprice);

    total.Text = Convert.ToString(Convert.ToDecimal(unitprice.Text) * numberofunit.Value);

    string pepperkaloriekle = gizlikalori.Text;

    gizlikalori.Text = 
        Convert.ToString(Convert.ToDouble(pepperkaloriekle) - pepperkalori);

    amountofcalorie.Text = 
        Convert.ToString(Convert.ToDecimal(gizlikalori.Text) * numberofunit.Value);
}

This Code is pepper’s checkbox code.

This is the form of my application.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:12:24+00:00Added an answer on May 28, 2026 at 2:12 am

    You should really try to separate the calculation logic from the UI logic (the form). Then the things will become much clearer:

    // Get values from the text boxes
    decimal up = Convert.ToDecimal(unitprice.Text);
    decimal calories = Convert.ToDecimal(gizlikalori.Text);
    decimal tot, totCalories;
    
    // Do the calculation
    if (pepper.Checked) {
        up = up + pepperprice;
        calories = calories + pepperkalori;
    }
    tot = up * numberofunit.Value;
    totCalories = calories * numberofunit.Value;
    
    // Assign the results to text boxes
    unitprice.Text = up.ToString();
    total.Text = tot.ToString();
    gizlikalori.Text = calories.ToString();
    amountofcalorie.Text = totCalories.ToString();
    

    What you do wrong, is that you subtract the pepper price and pepper calories from the unit price and the unit calories if no pepper is selected. However, the unit price (and calories) are without the pepper already!

    I do not see when you are performing this calculation, however if you perform it every time you are increasing the number of units, then you would be adding the pepper price each time! It would probaly be better to have a separate variable for the base unit price that remains unchanged when you check additions. Then always start the calculation from the base unit price.

    In addition, you are mixing many different number types. This makes no sense.

    The next step to enhance the code even more would be to create a separate class for the calculations. You could also use data binding. This would remove completely the need for doing conversions. See my answer to the following post
    : manipulating-textbox-variables-in-calculations

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a small android Jump and Run game but my problem
Trying to make a small countdown timer in my app but it's not working.
I am trying to make a small application for my arm target. I have
I finished my small application and I am trying to make sure I have
I'm trying to make an small tower defender game in Java. I have a
I am trying to make a small thread example. I want to have a
I'm trying to make a small calculator, as a personal project. I have a
I am trying to make small calculator in jquery but don't know where to
I'm trying to make a small game using both SFML and Box2D. I have
I am trying to make a small ASP.NET application where I have a GridView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.