For Loop and Reverse the result...HELP


C

cw bebop

HTML code:

<form id="Form1" method="post" runat="server">
<asp:TextBox id="TextBox1" style="Z-INDEX: 105; LEFT: 120px; POSITION:
absolute; TOP: 64px" runat="server" Width="144px"></asp:TextBox>
<asp:TextBox id="TextBox2" style="Z-INDEX: 106; LEFT: 480px; POSITION:
absolute; TOP: 64px" runat="server"></asp:TextBox>
<aspropDownList id="DropDownList1" style="Z-INDEX: 107; LEFT: 320px;
POSITION: absolute; TOP: 16px" runat="server">
<asp:ListItem Value="Select Number...">Select Number...</asp:ListItem>
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>

</aspropDownList>
<asp:Button id="Button1" style="Z-INDEX: 108; LEFT: 16px; POSITION:
absolute; TOP: 128px" runat="server" Text="COMPUTE"></asp:Button>
<DIV style="DISPLAY: inline; Z-INDEX: 109; LEFT: 448px; WIDTH: 56px;
POSITION: absolute; TOP: 16px; HEIGHT: 18px"
ms_positioning="FlowLayout"><FONT face="Verdana">YEARS</FONT></DIV>
<asp:Label id="Label1" style="Z-INDEX: 110; LEFT: 16px; POSITION:
absolute; TOP: 232px" runat="server"></asp:Label>
</form>

VS C# code behind I'm using:

private void Button1_Click(object sender, System.EventArgs e)
{
double amount;
string output = "";
int q;

if (DropDownList1.SelectedIndex > 0)
{
double ct = double.Parse(TextBox1.Text);
double salv = double.Parse(TextBox2.Text);
for (int i=1;i<DropDownList1.Items.Count;i++)
{
if (DropDownList1.Items.Selected)
{
string num= DropDownList1.Items.Value;
q = int.Parse(num);

for (int year=1; year<=q; year++)
{

amount = ct - (ct-salv)/year;

output += "AFTER " + (q-year+1) + " YEAR: " +"\t" + String.Format
("{0:C}", amount) + "<br>";

Label1.Text = output;
}

}
}
}


}

Problem(s):

Select a year from DropDownList, Enter the value 70000 for TextBox1 and
the value 10000 for TextBox2.

Would like the result to be

AFTER 1 YEAR: $58,000.00
AFTER 2 YEARS: $55,000.00
AFTER 3 YEARS: $50,000.00
AFTER 4 YEARS: $40,000.00

and so on...

Can anyone help correct my code to do this?

Is there anyway to use one For Loop instead of two in this code?

I'm looking for a simple solution.

Output should be:

After 1 year: any value
After 2 years: any value
After 3 years: any value

Thanks.

bebop




*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Ad

Advertisements

S

Shakir Hussain

Try this.

try
{
double amount;
int q;
double ct = double.Parse(TextBox1.Text);
double salv = double.Parse(TextBox2.Text);
q= int.Parse(DropDownList1.SelectedValue);

for (int year=1; year<=q; year++)
{
output = "";
output = "AFTER " + year.ToString() + " YEAR: " +"\t" +
String.Format
("{0:C}", ct - (ct-salv)/year) + "<br>";
Label1.Text = output;
}
}
catch
{
//catch exception here.
}

--
Shak
(Houston)




cw bebop said:
HTML code:

<form id="Form1" method="post" runat="server">
<asp:TextBox id="TextBox1" style="Z-INDEX: 105; LEFT: 120px; POSITION:
absolute; TOP: 64px" runat="server" Width="144px"></asp:TextBox>
<asp:TextBox id="TextBox2" style="Z-INDEX: 106; LEFT: 480px; POSITION:
absolute; TOP: 64px" runat="server"></asp:TextBox>
<aspropDownList id="DropDownList1" style="Z-INDEX: 107; LEFT: 320px;
POSITION: absolute; TOP: 16px" runat="server">
<asp:ListItem Value="Select Number...">Select Number...</asp:ListItem>
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>

</aspropDownList>
<asp:Button id="Button1" style="Z-INDEX: 108; LEFT: 16px; POSITION:
absolute; TOP: 128px" runat="server" Text="COMPUTE"></asp:Button>
<DIV style="DISPLAY: inline; Z-INDEX: 109; LEFT: 448px; WIDTH: 56px;
POSITION: absolute; TOP: 16px; HEIGHT: 18px"
ms_positioning="FlowLayout"><FONT face="Verdana">YEARS</FONT></DIV>
<asp:Label id="Label1" style="Z-INDEX: 110; LEFT: 16px; POSITION:
absolute; TOP: 232px" runat="server"></asp:Label>
</form>

VS C# code behind I'm using:

private void Button1_Click(object sender, System.EventArgs e)
{
double amount;
string output = "";
int q;

if (DropDownList1.SelectedIndex > 0)
{
double ct = double.Parse(TextBox1.Text);
double salv = double.Parse(TextBox2.Text);
for (int i=1;i<DropDownList1.Items.Count;i++)
{
if (DropDownList1.Items.Selected)
{
string num= DropDownList1.Items.Value;
q = int.Parse(num);

for (int year=1; year<=q; year++)
{

amount = ct - (ct-salv)/year;

output += "AFTER " + (q-year+1) + " YEAR: " +"\t" + String.Format
("{0:C}", amount) + "<br>";

Label1.Text = output;
}

}
}
}


}

Problem(s):

Select a year from DropDownList, Enter the value 70000 for TextBox1 and
the value 10000 for TextBox2.

Would like the result to be

AFTER 1 YEAR: $58,000.00
AFTER 2 YEARS: $55,000.00
AFTER 3 YEARS: $50,000.00
AFTER 4 YEARS: $40,000.00

and so on...

Can anyone help correct my code to do this?

Is there anyway to use one For Loop instead of two in this code?

I'm looking for a simple solution.

Output should be:

After 1 year: any value
After 2 years: any value
After 3 years: any value

Thanks.

bebop




*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
S

Shakir Hussain

Correction.

In my post i said,

Label1.Text = output;

It should be

Label1.Text += output;
 
C

cw bebop

You're close.


I'm still looking for the following result when
TextBox1 value = 70000

TextBox2 value = 10000

and dropdownlist1 = 5 years


AFTER 1 YEAR: $58,000.00

AFTER 2 YEARS: $55,000.00

AFTER 3 YEARS: $50,000.00

AFTER 4 YEARS: $40,000.00

AFTER 5 YEARS: $10,000.00

Any suggestions?

Thanks.

bebop




*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
C

cw bebop

Ignore previous reply.

I'm still looking for the following result when
TextBox1 value = 70000

TextBox2 value = 10000

and dropdownlist1 = 5 years


AFTER 1 YEAR: $58,000.00

AFTER 2 YEARS: $55,000.00

AFTER 3 YEARS: $50,000.00

AFTER 4 YEARS: $40,000.00

AFTER 5 YEARS: $10,000.00

Any suggestions?

Thanks.

bebop

c# code behind:

private void Button1_Click(object sender, System.EventArgs e)
{
try
{
//double amount;
int q;
double ct = double.Parse(TextBox1.Text);
double salv = double.Parse(TextBox2.Text);
q= int.Parse(DropDownList1.SelectedValue);

for (int year=1; year<=q; year++)
{
string output = "";
output = "AFTER " + year.ToString() + " YEAR: " +"\t" +
String.Format ("{0:C}", ct - (ct-salv)/year) + "<br>";
Label1.Text += output;
}
}
catch
{
//catch exception here.
}




}

HTML code:

<form id="Form1" method="post" runat="server">
<asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 96px; POSITION:
absolute; TOP: 48px" runat="server"></asp:Label>
<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 96px; POSITION:
absolute; TOP: 232px" runat="server"
Text="Button"></asp:Button>
<asp:TextBox id="TextBox1" style="Z-INDEX: 103; LEFT: 368px;
POSITION: absolute; TOP: 144px"
runat="server"></asp:TextBox>
<asp:TextBox id="TextBox2" style="Z-INDEX: 104; LEFT: 360px;
POSITION: absolute; TOP: 184px"
runat="server"></asp:TextBox>
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 105; LEFT:
352px; POSITION: absolute; TOP: 96px"
runat="server">
<asp:ListItem Value="Select">Select</asp:ListItem>
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>
</asp:DropDownList>
</form>



*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
S

Simon Smith

You need to work out what formula you want to implement. The formula you
are implementing is:
Year X = 70000 - (70000 - 10000) / X

I don't think that this is the formula you want - at least it won't give
the answers you've shown. (I'm not sure what formula would give the answers
you've shown; it's definitely not linear and doesn't look like if follows
any of the e.g. depreciation formula's I know of).
If you have a follow-up to this, please quote some of the context so that
we can see what you're talking about and give reasonable responses.

Simon Smith
simon dot s at ghytred dot com
www.ghytred.com/NewsLook - NNTP for Outlook
 
Ad

Advertisements

H

Hans Kesting

cw bebop said:
Ignore previous reply.

I'm still looking for the following result when
TextBox1 value = 70000

TextBox2 value = 10000

and dropdownlist1 = 5 years


AFTER 1 YEAR: $58,000.00

AFTER 2 YEARS: $55,000.00

AFTER 3 YEARS: $50,000.00

AFTER 4 YEARS: $40,000.00

AFTER 5 YEARS: $10,000.00

Any suggestions?

Thanks.

bebop

c# code behind:

private void Button1_Click(object sender, System.EventArgs e)
{
try
{
//double amount;
int q;
double ct = double.Parse(TextBox1.Text);
double salv = double.Parse(TextBox2.Text);
q= int.Parse(DropDownList1.SelectedValue);

for (int year=1; year<=q; year++)
{
string output = "";
output = "AFTER " + year.ToString() + " YEAR: " +"\t" +
String.Format ("{0:C}", ct - (ct-salv)/year) + "<br>";
Label1.Text += output;
}
}
catch
{
//catch exception here.
}
}

change the calculation from
ct - (ct-salv)/year
to
ct - (ct-salv)/(q+1-year)


Hans Kesting
 
Ad

Advertisements

C

cw bebop

Hans

Very close.

After 5 Years the result is correct:

AFTER 1 YEAR: $58,000.00

AFTER 2 YEARS: $55,000.00

AFTER 3 YEARS: $50,000.00

AFTER 4 YEARS: $40,000.00

AFTER 5 YEARS: $10,000.00


Except that if the user selects the first year (1) from the DropDownList

and has TextBox1 value= 70000 and TextBox2 value= 10000

I get the following result:

AFTER 1 YEAR: $10000

when the result should be:

AFTER 1 YEAR: $58,000.00

Any suggestions?

bebop




*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top