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 6670691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:17:55+00:00 2026-05-26T03:17:55+00:00

DinnerFun dinnerFun = new DinnerFun { PeepQty = (int)nudPeepQty.Value }; I am creating a

  • 0
DinnerFun dinnerFun = new DinnerFun { PeepQty = (int)nudPeepQty.Value };

I am creating a new object of the DinnerFun class and trying to assign the value from the numeric up down object from the form to the int variable PeepQty.

When I go into debug mode, I can see that sure enough nudPeepQty has a numeric value, but it is never assigned to PeepQty, and my ending calculation always ends as 0.

As the problem might be something related to something I’ve done outside this line of code, I will add the rest of my project below:

DinnerParty.cs

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MonuEventPlanning
{
    class DinnerFun
    {
        const int FoodCost = 25;
        public int PeepQty;
        decimal CostOfBeverage;
        decimal CostOfDecorations;
        decimal TotalCost; 

        public void CalcDrinks(bool HealthOption)
        {
            if (HealthOption)
            {
                CostOfBeverage = 5M;
            }
            else
            {
                CostOfBeverage = 20M;
            }
        }

        public void CalcDecorations(bool FancyOption)
        {
            if (FancyOption)
            {
                CostOfDecorations = (PeepQty * 15M) + 50M; 
            }
            else
            {
                CostOfDecorations = (PeepQty * 7.5M) + 30M; 
            }
        }

        public decimal CalcTotalCost(bool HealthyOption)
        {
            if (HealthyOption)
            {
                TotalCost = (CostOfDecorations + CostOfBeverage) * .95M;
                return TotalCost; 
            }
            else
            {
                TotalCost = (CostOfBeverage + CostOfDecorations) + (PeepQty*25M);
                return TotalCost; 
            }
        }
    }
}

————Form1.cs ————-

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MonuEventPlanning
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void btnCalc_Click(object sender, EventArgs e)
        {
            DinnerFun dinnerFun = new DinnerFun { PeepQty = (int)nudPeepQty.Value };
            dinnerFun.CalcDrinks(cbxHealthy.Checked);
            dinnerFun.CalcDrinks(cbxFancy.Checked);
            DisplayCost(); 
        }

        public void DisplayCost()
        {
            DinnerFun dinnerFun = new DinnerFun(); 
            tbxDisplayCost.Text = dinnerFun.CalcTotalCost(cbxHealthy.Checked).ToString("c"); 
        }
    }
}
  • 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-26T03:17:56+00:00Added an answer on May 26, 2026 at 3:17 am

    The issue is that you are creating another DinnerFun that is not the same as the first one. Naturally the DinnerFun object in DisplayCost will have zero for the property value. Perhaps you meant this…

        private void btnCalc_Click(object sender, EventArgs e)
        {
            DinnerFun dinnerFun = new DinnerFun { PeepQty = (int)nudPeepQty.Value };
            dinnerFun.CalcDrinks(cbxHealthy.Checked);
            dinnerFun.CalcDrinks(cbxFancy.Checked);
            DisplayCost(dinnerFun); 
        }
    
        public void DisplayCost(DinnerFun dinnerFun)
        {
            tbxDisplayCost.Text = dinnerFun.CalcTotalCost(cbxHealthy.Checked).ToString("c"); 
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Honestly... I haven't got a clue what I'm doing wrong... I get the error
I am calling a method that returns a decimal, which I need to display

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.