User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 427,378 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,045 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser: Programming Forums
Views: 701 | Replies: 7
Reply
Join Date: Feb 2008
Posts: 11
Reputation: manutd4life230 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
manutd4life230 manutd4life230 is offline Offline
Newbie Poster

ARRAY help

  #1  
Mar 3rd, 2008
create an array of marks [1..5] then create a while loops to ask the user for 5 marks then displayed all stired marks.

  1. program marks;
  2. var
  3. mark:array[1..5] of integer;
  4. x:integer;
  5. counter:integer;
  6. Begin
  7. counter:=1;
  8. x:=1;
  9. while (counter<=5) do
  10. begin
  11. writeln('input marks');
  12. readln(mark[x]);
  13. x:=x+1;
  14. counter:=counter+1;
  15. end;
  16.  
  17. writeln(mark[3]);
  18.  
  19. end.

thankx in advanced for an help
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Posts: 69
Reputation: ExplainThat is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
ExplainThat ExplainThat is offline Offline
Junior Poster in Training

Re: ARRAY help

  #2  
Mar 4th, 2008
Not sure why you have two integer variables x and Counter. Surely, you could work with Counter alone, couldn't you?
Reply With Quote  
Join Date: Dec 2007
Posts: 26
Reputation: manutd4life is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
manutd4life manutd4life is offline Offline
Light Poster

Re: ARRAY help

  #3  
Mar 4th, 2008
Originally Posted by ExplainThat View Post
Not sure why you have two integer variables x and Counter. Surely, you could work with Counter alone, couldn't you?


ok i'll work with one integer, but its became a bit complicated. you'll have to make the sum of all the values stored in the array.

  1. program array_sum;
  2. Uses wincrt;
  3. var
  4. nums:array[1..10] of integer;
  5. index:integer;
  6. Sum:integer;
  7. Begin
  8. index:=1;
  9. writeln('Input marks');
  10. while (index<=10) do
  11. Begin
  12. Readln(nums[index]);
  13. index:=index+1;
  14. end;
  15.  
  16. index:=1;
  17. while (index<=10) do
  18. Begin
  19. sum:=(nums[index]);
  20. index:=index+1
  21. end;
  22. writeln('sum',sum);
  23. end.

hope will get a quick reply
Reply With Quote  
Join Date: Dec 2007
Posts: 26
Reputation: manutd4life is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
manutd4life manutd4life is offline Offline
Light Poster

Re: ARRAY help

  #4  
Mar 4th, 2008
dont no what to put there

  1. sum:=(nums[index]);
Reply With Quote  
Join Date: Sep 2007
Posts: 69
Reputation: ExplainThat is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
ExplainThat ExplainThat is offline Offline
Junior Poster in Training

Re: ARRAY help

  #5  
Mar 4th, 2008
  1. program array_sum;
  2. Uses wincrt;
  3. var
  4. nums:array[1..10] of integer;
  5. index:integer;
  6. Sum:integer;
  7. Begin
  8. sum:=0;//Delphi initializes local variables. Not sure if your Pascal compiler does
  9. index:=1;
  10. writeln('Input marks');
  11. while (index<=10) do
  12. Begin
  13. Readln(nums[index]);
  14. sum:=sum + nums[index];
  15. //you can update sum in the input loop - no need for a separate loop
  16. index:=index+1;
  17. end;
  18. writeln('sum',sum);
  19. end.

As a general observation for loops are more efficient - if you know you are working with 10 inputs. If this number is liable to be variable you might need to put in a test for an invalid input and break out of the loop prematurely. In any case, I would suggest some means of allowing for a premature break.

Better use a variable name other than Index - if it clashes with an object property that is in scope, for instance, you can end up with a hard to trace bug.
Reply With Quote  
Join Date: Dec 2007
Posts: 26
Reputation: manutd4life is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
manutd4life manutd4life is offline Offline
Light Poster

Re: ARRAY help

  #6  
Mar 4th, 2008
all work perfectly.
Thankx for ur help.
A+
Reply With Quote  
Join Date: Dec 2007
Posts: 26
Reputation: manutd4life is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
manutd4life manutd4life is offline Offline
Light Poster

Re: ARRAY help

  #7  
Mar 4th, 2008
u no vb.net
explain that
Reply With Quote  
Join Date: Sep 2007
Posts: 69
Reputation: ExplainThat is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
ExplainThat ExplainThat is offline Offline
Junior Poster in Training

Re: ARRAY help

  #8  
Mar 5th, 2008
Yes, but I don't often find time to survey more than one forum here. Try posting to the VB.NET forum - someone is bound to help out.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Pascal and Delphi Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Pascal and Delphi Forum

All times are GMT -4. The time now is 4:00 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC