create an array of marks [1..5] then create a while loops to ask the user for 5 marks then displayed all stired marks.

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

Recommended Answers

All 7 Replies

Not sure why you have two integer variables x and Counter. Surely, you could work with Counter alone, couldn't you?

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.

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

dont no what to put there

sum:=(nums[index]);
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.

all work perfectly.
Thankx for ur help.
A+

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.