# Calculating a cost based on textbox quantity greater than 10 RSS

## 8 replies

Last post Jan 09, 2013 03:37 PM by 12avi

• Russ08

Member

4 Points

24 Posts

### Calculating a cost based on textbox quantity greater than 10

Nov 20, 2012 08:18 AM|Russ08|LINK

I duped! I am developing a publishing website and allow clients to fill in a form to calculate their own price quote on formatting an ebook based on the info they submit. In the case below I want to charge \$3 for every image over 10 (ex: up to 10 at no cost), and show the price quote in Label1 on btnCalculate_Click event.

Example: If client types "11" in textbox for image quantity, I want to charge them \$3 and show that in Label1 (10 free + 1 @ \$3.00). If the choose 12, I want to charge \$6.00 (10 free + 2 @\$3.00). I have written code to be able to charge for all quantity submitted, but cannot figure how to use the ">" (greater than) to eliminate the first 10.

Following is the latest code I am trying, but cannot get to work. Any suggestions of what I am missing would be much appreciated. Thanks!

This existing code does not show any error messages; it just doesn't work.

protected void btnCalculate_Click(object sender, EventArgs e)
{
int n5, i, total;
n5 = 3;
i = Convert.ToInt32((TextBox1.Text.Length) > 10);

if (int.Parse(TextBox1.Text) > 10)
{
total = (i * n5);
Label1.Text = Convert.ToString(total);
}
else
{
total = 0;
Label1.Text = Convert.ToString(total);
}

}

• Dan Bracuk

Participant

1882 Points

1056 Posts

### Re: Calculating a cost based on textbox quantity greater than 10

Nov 20, 2012 08:21 AM|Dan Bracuk|LINK

What is this line supposed to accomplish?

i = Convert.ToInt32((TextBox1.Text.Length) > 10);

• Russ08

Member

4 Points

24 Posts

### Re: Calculating a cost based on textbox quantity greater than 10

Nov 20, 2012 11:50 AM|Russ08|LINK

Hi Dan,

Thanks for your fast reply. In reference to your question...

Obviously not what I thought. It's supposed to take the data input from TextBox1 (only numbers greater than 10). Than I attempted to call it in the if statement "total = (i * n5);" which is supposed to translate to TextBox1 total that is greater than 10 is to be multiplied by n5, which I've declared as the number 3 (for the \$3.00 I am charging for each image of 11 or more).

I used an if statement because it should only call it for totals of 11 or more. I tried quite a few different scenarios, but none that mutilplied it properly. This code I have submitted doesn't work at all, although I know the else statement works because it did with all other coding I tried.

I am obviously a novice with C# programming, so please be easy on me (LOL).

Thanks! Russ

• Russ08

Member

4 Points

24 Posts

### Re: Calculating a cost based on textbox quantity greater than 10

Nov 20, 2012 12:15 PM|Russ08|LINK

Hi Dan,

I figured it out. I was way off with the code I submitted, but went back to the original code which I tried and tweaked it, I  got it to do what I want.

Thanks!

• Dan Bracuk

Participant

1882 Points

1056 Posts

### Re: Calculating a cost based on textbox quantity greater than 10

Nov 20, 2012 12:29 PM|Dan Bracuk|LINK

#### Russ08

I am obviously a novice with C# programming, so please be easy on me (LOL).

You are never too new to learn good habits.   One of my favourites is, when in doubt, look at the data.  Do you know how to use the Visual Studio debugger?  It's an excellent piece of kit.

• oned_gk

All-Star

51141 Points

15063 Posts

### Re: Calculating a cost based on textbox quantity greater than 10

Nov 20, 2012 09:15 PM|oned_gk|LINK

Maybe

```int n5, i, total;
n5 = 3;
i = int.Parse(TextBox1.Text);

if (i > 10)
{
total = (i * n5);
Label1.Text = total.ToString();
}
else
{
total = 0;
Label1.Text = total.ToString();
}```

Programming to simplify, don't look for difficult way
Suwandi - Non Graduate Programmer
• Russ08

Member

4 Points

24 Posts

### Re: Calculating a cost based on textbox quantity greater than 10

Nov 20, 2012 10:47 PM|Russ08|LINK

Hi oned_gk,

Although I figured it out, you code works and is a little shorter than mine. THANKS!!

• Russ08

Member

4 Points

24 Posts

### Re: Calculating a cost based on textbox quantity greater than 10

Nov 20, 2012 10:48 PM|Russ08|LINK

Hi Dan,

Yes, little by little I am figuring it all out. Thanks for the ecouragement!!

• 12avi

Member

2 Points

12 Posts

### Re: Calculating a cost based on textbox quantity greater than 10

Jan 09, 2013 03:37 PM|12avi|LINK

Hi, I think this code:-

```if (i > 10)
{
total = (i * n5);
Label1.Text = total.ToString();
}```

```if (i > 10)