473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

where is the error?

Can anyone tell me why the for cycle does not work? I only get the
multiplication, but the for does not start:
protected double CalFutureValue(double initial_value, double
interest_rate, int years)
{
double future_value =0;
double alfa = 0;
for (int i = 1; i <= years; i++)
{
alfa = (initial_value * (interest_rate / 100)) ;
valore_futuro = (alfa + initial_value);
}
}

the fact is that i don't get any error message, it's just not making
the calculation.
Thanks

Sep 25 '07 #1
7 1073
vinnie wrote:
Can anyone tell me why the for cycle does not work? I only get the
multiplication, but the for does not start:
protected double CalFutureValue(double initial_value, double
interest_rate, int years)
{
double future_value =0;
double alfa = 0;
for (int i = 1; i <= years; i++)
{
alfa = (initial_value * (interest_rate / 100)) ;
valore_futuro = (alfa + initial_value);
}
}

the fact is that i don't get any error message, it's just not making
the calculation.
Thanks
It suggests you are not assigning years - have you tried for test purposes:

years=100;
for (int i = 1; i <= years; i++)
Sep 25 '07 #2
PS if you break and debug on the 'for' you will get the values and find
out why the thing isnt working as well in any case but you knew that did
you not?
Sep 25 '07 #3
vinnie <ce**********@gmail.comwrote:
Can anyone tell me why the for cycle does not work? I only get the
multiplication, but the for does not start:

protected double CalFutureValue(double initial_value, double
interest_rate, int years)
{
double future_value =0;
double alfa = 0;
for (int i = 1; i <= years; i++)
{
alfa = (initial_value * (interest_rate / 100)) ;
valore_futuro = (alfa + initial_value);
}
}

the fact is that i don't get any error message, it's just not making
the calculation.
Thanks
Well, that isn't your actual code - it wouldn't compile, as you don't
have a return statement.

Could you post your *actual* code, preferably in the context of a short
but complete program which demonstrates the problem?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 25 '07 #4
On Sep 25, 6:14 pm, Jon Skeet [C# MVP] <sk...@pobox.comwrote:
>
Well, that isn't your actual code - it wouldn't compile, as you don't
have a return statement.

Could you post your *actual* code, preferably in the context of a short
but complete program which demonstrates the problem?

--
Jon Skeet - <sk...@pobox.com>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
I'm just trying to calculate the final value, when given a number of
years, an initial amount, and an interest rate, i get the final
amount payed.
I did inserted the "return future_value" but it did not work anyway.

Thanks

Sep 25 '07 #5
vinnie wrote:
I'm just trying to calculate the final value, when given a number of
years, an initial amount, and an interest rate, i get the final
amount payed.
Yes. That general description is apparent from the code you posted.
But that's not at all the information Jon asked you to provide.
I did inserted the "return future_value" but it did not work anyway.
It's obvious from the code you posted that the code you posted wasn't
simply copy and pasted from the actual program. The missing return
statement and the mixed naming ("future_value" versus "valore_futuro")
make that clear enough.

So, any comment on the code you posted may or may not actually be
relevant to whatever problem you're actually having. We'd be commenting
on what you posted, not the code you're actually using.

That said, in the code you posted, there is no variable that actually
depends on the iteration of the loop. All that the loop does is keep
calculating the same "alfa" and "valore_futuro" over and over. The
inputs to the "alfa" calculation don't change, and so the inputs for
"valore_futuro" don't change either ("alfa" being the only one modified
within the loop). Thus the calculated value for "valore_futuro" is
exactly the same each time through the loop.

I leave it to the CPAs to decide whether your algorithm, even if
modified so that the code in the loop does useful work, is actually a
proper calculation of "future value". But as a programmer I can tell
you that the loop you posted is useless.

If you want it to do something useful, you need to explain better the
exact calculation you're trying to implement.

And if you want anyone to comment on the code you're _using_ you need to
actually post that code. And for best assistance you need to post code
that is "concise-but-complete", meaning it contains _nothing_ not
directly related to reproducing the problem, but it at the same time is
ready to be compiled as-is, without any additional work on the part of
someone trying to compile it.

This latter is something Jon already asked you once to provide. If you
expect any real help, you need to be willing to work with the people
offering help to provide the details they need to help you.

Pete
Sep 25 '07 #6
hi:
the reason may be :
1st, years equal 0, so no cycle.
2nd,the values of the initial_value and interest_rate is make the
cycle seem doing nothing when you run this code.

but ,suggest you debugging step by step!!
On 9 26 , 5 49 , vinnie <centro.ga...@gmail.comwrote:
Can anyone tell me why the for cycle does not work? I only get the
multiplication, but the for does not start:

protected double CalFutureValue(double initial_value, double
interest_rate, int years)
{
double future_value =0;
double alfa = 0;
for (int i = 1; i <= years; i++)
{
alfa = (initial_value * (interest_rate / 100)) ;
valore_futuro = (alfa + initial_value);
}

}

the fact is that i don't get any error message, it's just not making
the calculation.
Thanks

Sep 26 '07 #7
On Sep 26, 2:42 am, chou <jimu8...@gmail.comwrote:
hi:
the reason may be :
1st, years equal 0, so no cycle.
2nd,the values of the initial_value and interest_rate is make the
cycle seem doing nothing when you run this code.

but ,suggest you debugging step by step!!

On 9 26 , 5 49 , vinnie <centro.ga...@gmail.comwrote:
How do i debug step by step?
sorry, i'm just at the begging

Sep 26 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've...
18
by: jabailo | last post by:
I wrote a program that loops through a file of records. It parses each line in the file and sends them to a web service that inserts them into an AS400DB2 database using Asynch calls. This is...
7
by: Yongsub Eric Shin | last post by:
Hi. I'm just a beginner in ASP.Net. I started writing codes and I keep on getting this Runtime Error page, where it says "Description: An application error occurred on the server. The current...
7
by: Britney | last post by:
Original code: this.oleDbSelectCommand1.CommandText = "SELECT TOP 100 user_id, password, nick_name, sex, age, has_picture, city, state, " + "country FROM dbo.users WHERE (has_picture = ?) AND (sex...
3
by: Yannick | last post by:
Hi, I try to execute request on a ms-access database but I have a problem with date. the "myDate" field's format is "date/time" my request is: SELECT myCode, myStuff, myDATE FROM myTable ...
12
by: Yannick | last post by:
Hi, I've got a problem accessing a ms-access db with a sql statement like this: SELECT * FROM laTable WHERE laDate = #05/21/2004# ; with asp.net (vb code) laTable contains a "laDate"...
9
by: Scott Ribe | last post by:
OK, I'm using a pool of worker threads that each have a connection (from my own software, no PHP or anything like that involved), and a connection is in a state where all queries fail. Looking back...
7
by: Swinky | last post by:
Mr. Browne's copy code on his web site has saved me. I have been struggling to copy a record with several related sub-form tables. I found code on his web site that copies a sub-form table,...
6
by: Liming | last post by:
Hi, In a typical 3 tier model (view layer, busines layer and data access layer) where do you handle your exceptions? do you let it buble up all the way to the .aspx pages or do you handle it in...
10
by: arial | last post by:
Hi, I am getting this error message: Incorrect syntax near the keyword 'where'. Description: An unhandled exception occurred during the execution of the current web request. Please review...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.