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
You have several issues here:
First of all, your
string cuis declared inside theifscope. It will not exist outside that scope. If you need to use it outside the scope of theif, declare it outside.Second, math operations cannot be applied to
strings. Why are you casting your numeric values to string? Your code should be: