473,569 Members | 2,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

For.....loop

53 New Member
Can anybody solve the query for me please

In June of 2005, Sammy puts $ 1,024 into a savings account and, each month thereafter, plans to deposit only half of what he saved in the previous month. Using a single for loop, write a program that will show that he will have deposited $ 2,047.50 into his account by the end of May 2006. Express your output as a dollar amount, with two decimal places.

Thanks
Dev
Dec 10 '06 #1
3 3546
sushma
4 New Member
Can anybody solve the query for me please

In June of 2005, Sammy puts $ 1,024 into a savings account and, each month thereafter, plans to deposit only half of what he saved in the previous month. Using a single for loop, write a program that will show that he will have deposited $ 2,047.50 into his account by the end of May 2006. Express your output as a dollar amount, with two decimal places.

Thanks
Dev


hi the solution for your problem is:

SQL> declare
2 present number(7,2):=10 24.00;
3 inc number(10,2);
4 final number(10,2);
5 mon number;
6 begin
7 final:=1024.00;
8 mon := months_between( to_date('may-06','mon-yy'),to_date('j une-05','mon-yy'));
9 for i in 1..mon loop
10 present :=present/2;
11 final := final+present;
12 dbms_output.put _line('savings in the month of '||i||'='||pres ent);
13 end loop;
14 dbms_output.put _line('final amount is : '||ltrim(to_cha r(final,'L99G99 9D99MI')));
15 end;
16 /
savings in the month of 1=512
savings in the month of 2=256
savings in the month of 3=128
savings in the month of 4=64
savings in the month of 5=32
savings in the month of 6=16
savings in the month of 7=8
savings in the month of 8=4
savings in the month of 9=2
savings in the month of 10=1
savings in the month of 11=.5
final amount is : $2,047.50

PL/SQL procedure successfully completed.


hope this helped you. if there are any issues let me know
Dec 13 '06 #2
pragatiswain
96 Recognized Expert New Member
hi the solution for your problem is:

SQL> declare
2 present number(7,2):=10 24.00;
3 inc number(10,2);
4 final number(10,2);
5 mon number;
6 begin
7 final:=1024.00;
8 mon := months_between( to_date('may-06','mon-yy'),to_date('j une-05','mon-yy'));
9 for i in 1..mon loop
10 present :=present/2;
11 final := final+present;
12 dbms_output.put _line('savings in the month of '||i||'='||pres ent);
13 end loop;
14 dbms_output.put _line('final amount is : '||ltrim(to_cha r(final,'L99G99 9D99MI')));
15 end;
16 /
savings in the month of 1=512
savings in the month of 2=256
savings in the month of 3=128
savings in the month of 4=64
savings in the month of 5=32
savings in the month of 6=16
savings in the month of 7=8
savings in the month of 8=4
savings in the month of 9=2
savings in the month of 10=1
savings in the month of 11=.5
final amount is : $2,047.50

PL/SQL procedure successfully completed.

hope this helped you. if there are any issues let me know
Can try this one too.

declare
ibaseAmt number(10,2);
iTotalAmt number(10,2);
iMonth Number(2);

Begin
ibaseAmt := 1024;
iMonth := 1;
iTotalAmt:=ibas eAmt;
dbms_output.put line('Month:'|| iMonth ||',Deposit Amt For This

month: $'|| ibaseAmt ||', Total Amount Deposited: $' || iTotalAmt);
While (iTotalAmt < 2047.50 )

ibaseAmt := ibaseAmt/2;
iTotalAmt:= iTotalAmt + ibaseAmt;
iMonth := iMonth + 1;
dbms_output.put line('Month:'|| iMonth ||',Deposit Amt For

This month: $'|| ibaseAmt ||', Total Amount Deposited: $' ||

iTotalAmt);

do
End;
Dec 13 '06 #3
Deven Oza
53 New Member
hi the solution for your problem is:

SQL> declare
2 present number(7,2):=10 24.00;
3 inc number(10,2);
4 final number(10,2);
5 mon number;
6 begin
7 final:=1024.00;
8 mon := months_between( to_date('may-06','mon-yy'),to_date('j une-05','mon-yy'));
9 for i in 1..mon loop
10 present :=present/2;
11 final := final+present;
12 dbms_output.put _line('savings in the month of '||i||'='||pres ent);
13 end loop;
14 dbms_output.put _line('final amount is : '||ltrim(to_cha r(final,'L99G99 9D99MI')));
15 end;
16 /
savings in the month of 1=512
savings in the month of 2=256
savings in the month of 3=128
savings in the month of 4=64
savings in the month of 5=32
savings in the month of 6=16
savings in the month of 7=8
savings in the month of 8=4
savings in the month of 9=2
savings in the month of 10=1
savings in the month of 11=.5
final amount is : $2,047.50

PL/SQL procedure successfully completed.


hope this helped you. if there are any issues let me know

Hi Shushma,
it works ,
Thank you very much
-Deven
Dec 18 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2925
by: Charles Alexander | last post by:
Hello I am new to php & MySQL - I am trying to retrieve some records from a MySQL table and redisplay them. The data in list form looks like this: Sample_ID Marker_ID Variation G23_NA17192.fsa rs7374540 A/C I23_Control.fsa rs7374540 C/C
3
5252
by: Anand Pillai | last post by:
This is for folks who are familiar with asynchronous event handling in Python using the asyncore module. If you have ever used the asyncore module, you will realize that it's event loop does not have a programmable exit condition. It keeps looping till the channels in its socket map (a dictionary) are closed and don't have any pending...
43
5542
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a fallacy built on the assumption of mythical infinite all powerfull machines. In reality we deal with finite machines that are capable of two states in...
5
7290
by: Martin Schou | last post by:
Please ignore the extreme simplicity of the task :-) I'm new to C, which explains why I'm doing an exercise like this. In the following tripple nested loop: int digit1 = 1; int digit2 = 0; int digit3 = 0; for( ; digit1 < 5 ; digit1++ ) {
32
4605
by: Toby Newman | last post by:
At the page: http://www.strath.ac.uk/IT/Docs/Ccourse/subsection3_8_3.html#SECTION0008300000000000000 or http://tinyurl.com/4ptzs the author warns: "The for loop is frequently used, usually where the loop will be traversed a fixed number of times. It is very flexible, and novice programmers should take care not to abuse the power it...
2
2670
by: Alex | last post by:
Compiler - Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland Linker - Turbo Incremental Link 5.65 Copyright (c) 1997-2002 Borland Platform - Win32 (XP) Quite by accident I stumbled across some wierd loop behavior. With the pasted code I receive the output that follows. I realize that the code is broken, because the inner loop...
3
3511
by: Ben R. | last post by:
In an article I was reading (http://www.ftponline.com/vsm/2005_06/magazine/columns/desktopdeveloper/), I read the following: "The ending condition of a VB.NET for loop is evaluated only once, while the C# for loop ending condition is evaluated on every iteration." Is this accurate? I don't understand how you could get away without...
32
2570
by: cj | last post by:
When I'm inside a do while loop sometimes it's necessary to jump out of the loop using exit do. I'm also used to being able to jump back and begin the loop again. Not sure which language my memories are of but I think I just said loop somewhere inside the loop and it immediately jumped back to the start of the loop and began again. I can't...
16
3501
by: Claudio Grondi | last post by:
Sometimes it is known in advance, that the time spent in a loop will be in order of minutes or even hours, so it makes sense to optimize each element in the loop to make it run faster. One of instructions which can sure be optimized away is the check for the break condition, at least within the time where it is known that the loop will not...
2
19297
ADezii
by: ADezii | last post by:
If you are executing a code segment for a fixed number of iterations, always use a For...Next Loop instead of a Do...Loop, since it is significantly faster. Each pass through a Do...Loop that iterates a specified number of times, requires you to also implement or decrement some sort of Loop Counter, while a For...Next Loop does that work for you....
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7970
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.