I have to create a program that uses 2 loops to calculate the average of any number of grades, and run the program any number of times. So far this is what I have, I'm sure it's at least 99% wrong, but if someone could please help me get in the right direction, that would be great.

Var num, sum, max, i, average : double, n:integer

Begin
     if (num>0) and (num<=max) then begin
     for i := 1 to num do begin
          write ('Enter grade');
          readln(grades);
     end;
     average := (sum/n);
     writeln ('The average is' , average);
End.

Var num, sum, max, i, average : double, n:integer

Begin
if (num>0) and (num<=max) then begin
for i := 1 to num do begin
write ('Enter grade');
readln(grades);
end;
average := (sum/n);
writeln ('The average is' , average);
End.

Just some questions to point you

- where does "num" come from? Is this meant to be a program or a function where num is passed in as a parameter. If this is a program then num is undefined and you will crash & burn.

- you divide by n, i think you mean to divide by "num" as n is also undefined

- is it a good idea to use "num"? An alternative is to use a "repeat - until" loop so that the user does not have to specify what num is first, just repeat until, say, the user enters a blank line. Of course you then have to set "n:=0;" before starting and set "n:=n+1;" at each loop (except the last one).

- again "sum" is undefined, you need to set it before starting & you need to do somthing with the "grades" value that you read in. ie convert it to a number & add it to sum.

- watch your indentation it will save you from a lot of grief with begin-end. In the above you should have
if (num...etc) then
begin
for etc... do
begin
etc
end
dostuff
end

i need how to find the average of even and odd number up to 100 number
that i want to use pascal programming

thanks

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.