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

  • Home
  • SEARCH
  • 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 9244077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:56:31+00:00 2026-06-18T08:56:31+00:00

public void button1_Click(object sender, EventArgs e) { if (cushioncheckBox.Checked) { decimal totalamtforcushion = 0m;

  • 0
public void button1_Click(object sender, EventArgs e)
{
    if (cushioncheckBox.Checked)
    {
        decimal totalamtforcushion = 0m;

        totalamtforcushion = 63m * cushionupDown.Value;
        string cu = totalamtforcushion.ToString("C");
        cushioncheckBox.Checked = false;
        cushionupDown.Value = 0;
    }

    if (cesarbeefcheckBox.Checked)
    {
        decimal totalamtforcesarbeef = 0m;
        totalamtforcesarbeef = 1.9m * cesarbeefupDown.Value;
        string cb = totalamtforcesarbeef.ToString("C"); 
        cesarbeefcheckBox.Checked = false;
        cesarbeefupDown.Value = 0;

    }
}

So i have these codes. How do i add the two strings, cb and cu together? I’ve tried doing

decimal totalprice;
totalprice = cu + cb;

but it says the name does not exist in the context.
What should i do??

i’m using windows form btw

  • 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-06-18T08:56:32+00:00Added an answer on June 18, 2026 at 8:56 am

    You have several issues here:

    First of all, your string cu is declared inside the if scope. It will not exist outside that scope. If you need to use it outside the scope of the if, declare it outside.

    Second, math operations cannot be applied to strings. Why are you casting your numeric values to string? Your code should be:

    decimal totalamtforcushion = 0m;
    
    if (cushioncheckBox.Checked)
    {
        totalamtforcushion = 63m * cushionupDown.Value;
        //string cu = totalamtforcushion.ToString("C"); You don't need this
        cushioncheckBox.Checked = false;
        cushionupDown.Value = 0;
    }
    
    decimal totalamtforcesarbeef = 0m;
    if (cesarbeefcheckBox.Checked)
    {
        totalamtforcesarbeef = 1.9m * cesarbeefupDown.Value;
        //string cb = totalamtforcesarbeef.ToString("C");  you don't need this either
        cesarbeefcheckBox.Checked = false;
        cesarbeefupDown.Value = 0;
    
    }
    
    var totalprice = totalamtforcushion + totalamtforcesarbeef;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public void Button1_Click(object sender, EventArgs e) { String a = DropDownList1.SelectedItem.Value; String b =
I need to pass a string value from Form1 : public void button1_Click(object sender,
private void button1_Click(object sender, EventArgs e) { test(); } public void test() { Dictionary<string,
using System; public class ImageConverter { public void button1_Click(Object sender, RoutedEventArgs e) { string
I got the following code: string path = Environment.CurrentDirectory; private void button1_Click(object sender, EventArgs
I need help in creating a thread, C# winforms private void button1_Click(object sender, EventArgs
How can i stop keydown event in my current situation? private void button1_Click(object sender,
I want to convert this console code to form code: public void catching(string[] args)
Code: button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // fileReader(); new xyz().execute(); }//
button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { db.update(); } }); On line

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.