473,503 Members | 544 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 3542
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):=1024.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('june-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||'='||present);
13 end loop;
14 dbms_output.put_line('final amount is : '||ltrim(to_char(final,'L99G999D99MI')));
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):=1024.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('june-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||'='||present);
13 end loop;
14 dbms_output.put_line('final amount is : '||ltrim(to_char(final,'L99G999D99MI')));
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:=ibaseAmt;
dbms_output.putline('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.putline('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):=1024.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('june-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||'='||present);
13 end loop;
14 dbms_output.put_line('final amount is : '||ltrim(to_char(final,'L99G999D99MI')));
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
2911
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 ...
3
5244
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...
43
5527
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...
5
7282
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;...
32
4593
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...
2
2658
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...
3
3504
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,...
32
2554
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...
16
3490
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...
2
19288
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...
0
7203
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
7087
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
7334
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...
1
6993
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7462
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...
1
5014
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...
0
4675
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...
0
1514
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 ...
0
383
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.