Basic to intermediate help needed. 
Author Message
 Basic to intermediate help needed.



Quote:
> I'm sitting a Diploma in Information Communication Technology Level 5
at BOP
> Polytech.  We have to use Turbo Pascal 1.5.  I'm having trouble
getting a
> simple program to run propperly.  I can't figure out how to retrieve
the
> lowest & highest value from an array I've created.  I've attached a
copy of
> the source code for anyone who wants to have a look at it and tell me
where
> I'm going wrong.

> Cheers all

> Gavin.

I don't see anything wrong with it. It compiles and runs just fine on my
computer.
For the last line, you might consider

          Writeln('Average student mark = ', round (Marks/Count));

Div always truncates the nuimber.

--
Femme



Sat, 08 Oct 2005 20:31:29 GMT  
 Basic to intermediate help needed.



Quote:
> I'm sitting a Diploma in Information Communication Technology Level 5
at BOP
> Polytech.  We have to use Turbo Pascal 1.5.  I'm having trouble
getting a
> simple program to run propperly.  I can't figure out how to retrieve
the
> lowest & highest value from an array I've created.  I've attached a
copy of
> the source code for anyone who wants to have a look at it and tell me
where
> I'm going wrong.

> Cheers all

> Gavin.

Sorry I misread your question.

start by defining two proper variabeles

e.g.
Var, highestmark, lowestmark:integer;

In the loop where you calculate the sum of all marks, you can find the
highest and lowest value

     Begin
          Writeln;
          Marks := 0;
          highestmark:=0;
          lowestmark:=30000;
          For Loop := 1 to Count Do
          Begin
               Marks := Marks + Markno[Loop];
               if markno[loop]> highestmark then
highestmark:=markno[loop];
          .......similar for the lowest mark
          End;
          Writeln('Average student mark = ',Marks Div Count);
     End;



Sat, 08 Oct 2005 20:38:58 GMT  
 Basic to intermediate help needed.
hi femme,

i think there are several problems with the source.

try to enter '0' marks -> division by zero.

try to enter '20' marks -> program doesn't stop. -> 'out of bounds'

Quote:
> Sorry I misread your question.

> start by defining two proper variabeles

> e.g.
> Var, highestmark, lowestmark:integer;

> In the loop where you calculate the sum of all marks, you can find the
> highest and lowest value

>      Begin
>           Writeln;
>           Marks := 0;
>           highestmark:=0;
>           lowestmark:=30000;

assume:

mark[1] := 31000; mark[2] := 32000 ...

lowest ? ;-)

Quote:
>           For Loop := 1 to Count Do
>           Begin
>                Marks := Marks + Markno[Loop];
>                if markno[loop]> highestmark then
> highestmark:=markno[loop];
>           .......similar for the lowest mark
>           End;
>           Writeln('Average student mark = ',Marks Div Count);
>      End;

highest := markno[1];
lowest := highest;
marks := highest;

for loop := 2 to count do
begin
  ...
end;

of course in this case there is no need to use an array at all.

kind regards
jochen



Sat, 08 Oct 2005 21:18:51 GMT  
 Basic to intermediate help needed.



Quote:
> hi femme,

> i think there are several problems with the source.

> try to enter '0' marks -> division by zero.

> try to enter '20' marks -> program doesn't stop. -> 'out of bounds'

For user programs I usually let the user enter the value as a string.
Use the Val procedure to interpret the string and assign it's value to
the appropriate variabele.
I never make the program such that the user has to enter the number of
items on beforehand. It is better to count the number of items when they
are entered.

The best advice is probably that you can find the build-in help index by
entering shift F1

It is good to know how to build a very simple menu driven program.
e.g.

procedure mainmenu;
begin
repeat
  clrscr;
  writeln('a: choise 1');
  writeln('b: choise 2');
  writeln('ESC exit');
  case upcase(readkey) of
    'A': {code for choise a};
    'B': {code for choise b};
    #27:exit;
   else write(#7);
  end;
until false
end;

Quote:
> > Sorry I misread your question.

> > start by defining two proper variabeles

> > e.g.
> > Var, highestmark, lowestmark:integer;

> > In the loop where you calculate the sum of all marks, you can find
the
> > highest and lowest value

> >      Begin
> >           Writeln;
> >           Marks := 0;
> >           highestmark:=0;
> >           lowestmark:=30000;

> assume:

> mark[1] := 31000; mark[2] := 32000 ...

> lowest ? ;-)

> >           For Loop := 1 to Count Do
> >           Begin
> >                Marks := Marks + Markno[Loop];
> >                if markno[loop]> highestmark then
> > highestmark:=markno[loop];
> >           .......similar for the lowest mark
> >           End;
> >           Writeln('Average student mark = ',Marks Div Count);
> >      End;

> highest := markno[1];
> lowest := highest;
> marks := highest;

> for loop := 2 to count do
> begin
>   ...
> end;

> of course in this case there is no need to use an array at all.

> kind regards
> jochen



Sun, 09 Oct 2005 00:22:41 GMT  
 Basic to intermediate help needed.
How about this?  I'm not really a pascal person (this may not compile) but I
believe the concept is correct.

          LowMark := Highest Possible Mark { 100 Perhaps }
          HighMark := Lowest Possible Mark {    0 Perhaps }
          For Loop := 1 to Count Do
          Begin
                    if Markno[Loop] < LowMark Then
                              LowMark := Markno[Loop];
                    if Markno[Loop] > HighMark Then
                              HighMark := Markno[Loop];
          End;

Good Luck,
Jim.



Quote:
> I'm sitting a Diploma in Information Communication Technology Level 5 at
BOP
> Polytech.  We have to use Turbo Pascal 1.5.  I'm having trouble getting a
> simple program to run propperly.  I can't figure out how to retrieve the
> lowest & highest value from an array I've created.  I've attached a copy
of
> the source code for anyone who wants to have a look at it and tell me
where
> I'm going wrong.

> Cheers all

> Gavin.



Sun, 09 Oct 2005 21:29:39 GMT  
 Basic to intermediate help needed.
hi femme,

Quote:

> "Jochen" schreef
>> hi femme,

>> i think there are several problems with the source.

>> try to enter '0' marks -> division by zero.

>> try to enter '20' marks -> program doesn't stop. -> 'out of bounds'

> For user programs I usually let the user enter the value as a string.
> Use the Val procedure to interpret the string and assign it's value to
> the appropriate variabele.

sorry, but i think, i am misunderstood by you.

entering 0 in the op's program should result in a division by zero
error.

and entering something above 10 should give you an "out of range"
(bounds) error. of course only if "range checking" is "on".

the program won't really stop. writing something like "stop" to the
screen like the op did, doesn't really mean to terminate the program.

Quote:
> I never make the program such that the user has to enter the number of
> items on beforehand. It is better to count the number of items when
> they are entered.

ack. and there ist no need to do so in this case.

Quote:
> The best advice is probably that you can find the build-in help index
> by entering shift F1

ack.

Quote:
> It is good to know how to build a very simple menu driven program.
> e.g.

> procedure mainmenu;
> begin
> repeat
>   clrscr;
>   writeln('a: choise 1');
>   writeln('b: choise 2');
>   writeln('ESC exit');
>   case upcase(readkey) of
>     'A': {code for choise a};
>     'B': {code for choise b};
>     #27:exit;
>    else write(#7);
>   end;
> until false
> end;

i've seen such things ;-)

but is it usefull in this kind of quick query? probably a stop-mark (<0)
would be a finer solution.

count := 1
repeat
  write(count'. mark: '):
  readln(mark[count]);
  inc(count)
until (mark[count-1]<0) or (count>10)
dec(count);
...

as i already posted, there is no need to use the array type at all in
this special case.

- Show quoted text -

Quote:
>>> Sorry I misread your question.

>>> start by defining two proper variabeles

>>> e.g.
>>> Var, highestmark, lowestmark:integer;

>>> In the loop where you calculate the sum of all marks, you can find
>>> the highest and lowest value

>>>      Begin
>>>           Writeln;
>>>           Marks := 0;
>>>           highestmark:=0;
>>>           lowestmark:=30000;

>> assume:

>> mark[1] := 31000; mark[2] := 32000 ...

>> lowest ? ;-)

>>>           For Loop := 1 to Count Do
>>>           Begin
>>>                Marks := Marks + Markno[Loop];
>>>                if markno[loop]> highestmark then
>>> highestmark:=markno[loop];
>>>           .......similar for the lowest mark
>>>           End;
>>>           Writeln('Average student mark = ',Marks Div Count);
>>>      End;

>> highest := markno[1];
>> lowest := highest;
>> marks := highest;

>> for loop := 2 to count do
>> begin
>>   ...
>> end;

did you read this?

this is a general question. predefining highest/lowest values is bad
style (imo). it *might* be ueseful in assembler routines, where higest
and lowest values of registeres are machine dependend to speed up low
level routines.

best regards
jochen



Tue, 11 Oct 2005 05:40:22 GMT  
 Basic to intermediate help needed.
Hi Jochen

<snip>

Quote:
>> For user programs I usually let the user enter the value as a string.
>> Use the Val procedure to interpret the string and assign it's value
to
>> the appropriate variabele.

> sorry, but i think, i am misunderstood by you.

No I was just telling what I would do.

Quote:
> entering 0 in the op's program should result in a division by zero
> error.

> and entering something above 10 should give you an "out of range"
> (bounds) error. of course only if "range checking" is "on".

> the program won't really stop. writing something like "stop" to the
> screen like the op did, doesn't really mean to terminate the program.

A problem occurs when you enter a somthing that can't be interpreted as
an integer number
e.g.  "5.6"  or  "hello world"
This will cause an immediate crash.

<snip>

Quote:
> >> assume:

> >> mark[1] := 31000; mark[2] := 32000 ...

> >> lowest ? ;-)

I assumed that the marks were some sort of exam results, numbers between
1 and 10.
If the numbers can be higher than 30000 I would use longint instead of
integer.

Quote:
> >>>           For Loop := 1 to Count Do
> >>>           Begin
> >>>                Marks := Marks + Markno[Loop];
> >>>                if markno[loop]> highestmark then
> >>> highestmark:=markno[loop];
> >>>           .......similar for the lowest mark
> >>>           End;
> >>>           Writeln('Average student mark = ',Marks Div Count);
> >>>      End;

> >> highest := markno[1];
> >> lowest := highest;
> >> marks := highest;

> >> for loop := 2 to count do
> >> begin
> >>   ...
> >> end;

> did you read this?

> this is a general question. predefining highest/lowest values is bad
> style (imo). it *might* be ueseful in assembler routines, where higest
> and lowest values of registeres are machine dependend to speed up low
> level routines.

Yes, my immediate remark is that the code will not work if there are
zero marks entered. So you 'll have to make exeptions for that. In case
of dynamic arrays, the assignment  highest := markno'[1]; will lead to
an immediate crash if count = 0.

Writing user (proof) programs takes atleast 3 or 4 times longer than any
special purpose program for the same amount of code.

--
Femme



Tue, 11 Oct 2005 20:58:53 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Basic help needed again.

2. I need help programming a basic book library system

3. Basic help needed again.

4. Basic to Pascal::: Need Help!!!!!!!

5. Basic to Pascal::: Need Help!!!!!!!

6. BASIC, VISUAL BASIC, C++, DELPHI SOFTWARE FRO CHEAP PRICE

7. Need to Learn DB Basics with Delphi.

8. Need guide for writing a basic GL system

9. Intermediate (object) file generation in VB and Delphi

10. Linked list: intermediate solution

11. SQL problem (just for me, not for intermediate users)

12. Job - Toronto for Junior/Intermediate Programmer

 

 
Powered by phpBB® Forum Software