•
•
•
•
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 397,598 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 2,826 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:
Views: 650 | Replies: 7
![]() |
•
•
Join Date: Feb 2008
Posts: 11
Reputation:
Rep Power: 1
Solved Threads: 0
create an array of marks [1..5] then create a while loops to ask the user for 5 marks then displayed all stired marks.
thankx in advanced for an help
pascal Syntax (Toggle Plain Text)
program marks; var mark:array[1..5] of integer; x:integer; counter:integer; Begin counter:=1; x:=1; while (counter<=5) do begin writeln('input marks'); readln(mark[x]); x:=x+1; counter:=counter+1; end; writeln(mark[3]); end.
thankx in advanced for an help
•
•
Join Date: Sep 2007
Posts: 63
Reputation:
Rep Power: 1
Solved Threads: 6
Not sure why you have two integer variables x and Counter. Surely, you could work with Counter alone, couldn't you?
•
•
Join Date: Dec 2007
Posts: 25
Reputation:
Rep Power: 1
Solved Threads: 1
•
•
•
•
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.
pascal Syntax (Toggle Plain Text)
program array_sum; Uses wincrt; var nums:array[1..10] of integer; index:integer; Sum:integer; Begin index:=1; writeln('Input marks'); while (index<=10) do Begin Readln(nums[index]); index:=index+1; end; index:=1; while (index<=10) do Begin sum:=(nums[index]); index:=index+1 end; writeln('sum',sum); end.
hope will get a quick reply
•
•
Join Date: Sep 2007
Posts: 63
Reputation:
Rep Power: 1
Solved Threads: 6
pascal Syntax (Toggle Plain Text)
program array_sum; Uses wincrt; var nums:array[1..10] of integer; index:integer; Sum:integer; Begin sum:=0;//Delphi initializes local variables. Not sure if your Pascal compiler does index:=1; writeln('Input marks'); while (index<=10) do Begin Readln(nums[index]); sum:=sum + nums[index]; //you can update sum in the input loop - no need for a separate loop index:=index+1; end; writeln('sum',sum); 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.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Pascal and Delphi Marketplace
- Can I ghost a RAID array??? (Windows NT / 2000 / XP / 2003)
- Creating dynamic array structures (C++)
- Array limit (C)
- struct dynamic 2d array alloc (C)
- string to integer array transformation (C)
- Array (Visual Basic 4 / 5 / 6)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: Some Questions About Pascal (NOT H/W Help)
- Next Thread: Directly send file to another PC


Linear Mode