Recent

Author Topic: program help  (Read 7216 times)

qwerty123

  • Newbie
  • Posts: 2
program help
« on: October 30, 2016, 09:19:13 pm »
I can't get this program to run. If anyone can help it would be appreciated


program
cooking contest; //name of program//
var
company_name,team_name,winning_team,winning_company:string;
pres_score,palp_score,prep_score,i:integer;
counter:integer;
highest:real;//assigning variables//

company array[1..20] of string;
team array[1..20] of string;
score array[1..20] of real;//declaaring arrays//

begin
i=1;
writeln('please enter a company name');
readln(company_name);
readln();
while(company_name <>)

begin
company_name[1]
writeln('enter the team name associated with the entered company');
readln(team_name);
team=team_name;
writeln('enter points scored for presentation');
readln(pres_score);
writeln('enter points scored for palpability');
readln(palp_score);
writeln('enter points scored for preparation');
readln(prep_score);
score=pres_score+palp_score+prep_score;
i=i+1;
writeln('enter company name');
readln(company_name);
end
i=1;
highest=0;
while(i<=20) do
begin
highest:=score[1];
winning_company:=company_name[1];

winning_team:=team_name[1];
end;
i=i+1;
end;

writeln('the winning company is',winning_company);
writeln('the winning team is',winning_team);
writeln('the winning team scored',highest);
i=1;
counter:=0;
while(i<=20)
do
begin
if(score>=250 points)then
begin
counter=counter+1;
writeln('team has reccieved more than 250 points',team_name);
end;
i=i+1;
end;
writeln('the total amount of teams that recieved more than 250 points is',counter);
end.

« Last Edit: October 30, 2016, 09:33:50 pm by qwerty123 »

Bart

  • Hero Member
  • *****
  • Posts: 5713
    • Bart en Mariska's Webstek
Re: program help
« Reply #1 on: October 30, 2016, 09:26:51 pm »
Homework assignment?

What exactly goes wrong?
Does it compile?
Does it crash?
Does it not do what you want?
Why 3 arrays (instead of one array that can hold all relevant info)?

What do you want to achieve?
Write out in normal english an algorithm that solves the problem (I think you never did that).
Then traslate that to pseudo-code.
Then translate to Pascal.

At each step you can ask for help, but be specific (see above).


Please also: put your code inside code-tags (the button with # on it).
Now it's inreadable, since somewhere you used the letter i inside [], which turns any text after it into Italics.

Bart
« Last Edit: October 30, 2016, 09:31:32 pm by Bart »

qwerty123

  • Newbie
  • Posts: 2
Re: program help
« Reply #2 on: October 30, 2016, 09:38:39 pm »
Hi Bart
It is a homework assignment but the code was sent by the teacher as she told us the code was supposed to be functional and we just had to get it to run. However when I try to compile it multiple errors appear.

Bart

  • Hero Member
  • *****
  • Posts: 5713
    • Bart en Mariska's Webstek
Re: program help
« Reply #3 on: October 30, 2016, 09:39:21 pm »
I find that hard to believe.
Your teacher does not have a Pascal compiler, nor has he ever written Pascal?

  • A program name cannot contain spaces
  • Pascal is not C. To assign a value to a variable the ":=" operator is used.
  • The "=" operator means "is equal to".
  • The "<>" operator means "is not equal to" and it requires both a left and a right operand (line 15)
  • Each statement needs to be terminated with a semicolon (unless it is followed by "end" or "else").
  • The same goes for "end"
  • "while" expects "do" (line 17)
  • A single line with just a variable is not a pascal statement (line 20)
  • There is an unmatched "end" at line 45

For reference, here is your code inside code-tags and with proper indentation:

Code: Pascal  [Select][+][-]
  1. program cook contest; //name of program//
  2. var
  3.   company_name,team_name,winning_team,winning_company:string;
  4.   pres_score,palp_score,prep_score,i:integer;
  5.   counter:integer;
  6.   highest:real;//assigning variables//
  7.  
  8.   company array[1..20] of string;
  9.   team array[1..20] of string;
  10.   score array[1..20] of real;//declaaring arrays//
  11.  
  12. begin
  13.   i=1;
  14.   writeln('please enter a company name');
  15.   readln(company_name);
  16.   readln();
  17.   while(company_name <>)
  18.  
  19.   begin
  20.     company_name[1]
  21.     writeln('enter the team name associated with the entered company');
  22.     readln(team_name);
  23.     team[i]=team_name;
  24.     writeln('enter points scored for presentation');
  25.     readln(pres_score);
  26.     writeln('enter points scored for palpability');
  27.     readln(palp_score);
  28.     writeln('enter points scored for preparation');
  29.     readln(prep_score);
  30.     score[i]=pres_score+palp_score+prep_score;
  31.     i=i+1;
  32.     writeln('enter company name');
  33.     readln(company_name);
  34.   end
  35.   i=1;
  36.   highest=0;
  37.   while(i<=20) do
  38.   begin
  39.     highest:=score[1];
  40.     winning_company:=company_name[1];
  41.  
  42.     winning_team:=team_name[1];
  43.   end;
  44.   i=i+1;
  45.   end;
  46.  
  47.   writeln('the winning company is',winning_company);
  48.   writeln('the winning team is',winning_team);
  49.   writeln('the winning team scored',highest);
  50.   i=1;
  51.   counter:=0;
  52.   while(i<=20)
  53.   do
  54.   begin
  55.     if(score[i]>=250 points)then
  56.     begin
  57.       counter=counter+1;
  58.       writeln('team has reccieved more than 250 points',team_name[i]);
  59.     end;
  60.     i=i+1;
  61.   end;
  62.   writeln('the total amount of teams that recieved more than 250 points is',counter);
  63. end.
  64.  


Bart
« Last Edit: October 30, 2016, 09:54:05 pm by Bart »

lainz

  • Hero Member
  • *****
  • Posts: 4742
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: program help
« Reply #4 on: October 30, 2016, 10:27:41 pm »
Bart, maybe the homework is to correct the program, I get some of that homework in university (I'm not saying that this is from an university, can be any school grade). Teachers give you a code that works, but with errors that you need to solve. So basically if he reads your post you did his homework.

Bart

  • Hero Member
  • *****
  • Posts: 5713
    • Bart en Mariska's Webstek
Re: program help
« Reply #5 on: October 30, 2016, 11:31:29 pm »
Bart, maybe the homework is to correct the program ...

If that's the case, he needs to donate $50 to us.

TS could just try to "repair" based upon the error the compiler spits out.

I could delete my post, but that woud make this thread rather unreadable.

Bart

lainz

  • Hero Member
  • *****
  • Posts: 4742
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: program help
« Reply #6 on: October 30, 2016, 11:34:39 pm »
Sure that's a way to solve it. Other is try to solve in a paper with no compiler, is another methodology.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: program help
« Reply #7 on: October 30, 2016, 11:50:14 pm »
One of the (in my eyes) benefits of using pascal is the speed of compilation and the compiler being able to produce meaningful errors.

On an unrelated sidenote: With GCC i mostly have to wait for ages, and then get an error message for which i first need to figure out what the h*ll the compiler is trying to tell me. Interpreting gcc compiler error messages seems to be an actual form of art.

So compile, read error, fix error, goto next error until things compile. done. 5-10 minute job ?
« Last Edit: October 30, 2016, 11:52:06 pm by molly »

RAW

  • Hero Member
  • *****
  • Posts: 871
Re: program help
« Reply #8 on: October 31, 2016, 12:45:12 am »
What did I win ???
The teacher ??? Is she nice ???
 :P

Code: Pascal  [Select][+][-]
  1. PROGRAM WhoIsTheWinner;
  2.  {$APPTYPE CONSOLE} // LAZARUS-IDE
  3.  USES
  4.   Crt;
  5.  
  6.  VAR
  7.   strComp,
  8.   strTeam: String;
  9.  
  10.   iPresScore,
  11.   iPalpScore,
  12.   iPrepScore,
  13.   i,
  14.   iCount,
  15.   iHighest: Integer;
  16.  
  17.   arrComp : Array[1..20] Of String;
  18.   arrTeam : Array[1..20] Of String;
  19.   arrScore: Array[1..20] Of Integer;
  20.  
  21. BEGIN
  22.  i:= 1;
  23.  
  24.  Writeln('Please enter a company name:');
  25.  Readln(strComp);
  26.  
  27.   While (strComp <> '') And (i <= 20)
  28.   Do
  29.    Begin
  30.     arrComp[i]:= strComp;
  31.  
  32.     Writeln('Enter the team name associated with the entered company: ');
  33.     Readln (strTeam);
  34.      arrTeam[i]:= strTeam;
  35.  
  36.     Writeln('Enter points scored for presentation: ');
  37.     Readln (iPresScore);
  38.  
  39.     Writeln('Enter points scored for palpability: ');
  40.     Readln (iPalpScore);
  41.  
  42.     Writeln('Enter points scored for preparation: ');
  43.     Readln (iPrepScore);
  44.  
  45.      arrScore[i]:= iPresScore +iPalpScore +iPrepScore;
  46.  
  47.     i:= i +1;
  48.     ClrScr;
  49.  
  50.      If i <= 20
  51.      Then
  52.       Begin
  53.        Writeln('Please enter the next company name: ');
  54.        Readln(strComp);
  55.       End;
  56.    End;
  57.  
  58.  
  59.   If arrComp[1] <> ''
  60.   Then
  61.    Begin
  62.     iHighest:= 0;
  63.     i       := 1;
  64.  
  65.      While(i <= 20)
  66.      Do
  67.       Begin
  68.        If arrScore[i] > iHighest
  69.        Then iHighest:= arrScore[i];
  70.         i:= i +1;
  71.       End;
  72.  
  73.  
  74.     For i:= 1 To 20
  75.     Do
  76.      Begin
  77.       If arrScore[i] = iHighest
  78.       Then
  79.        Begin
  80.         Writeln('The winning company is : ',  arrComp[i]);
  81.         Writeln('The winning team is    : ',  arrTeam[i]);
  82.         Writeln('The winning team scored: ', arrScore[i]);
  83.         Writeln();
  84.         Writeln();
  85.        End;
  86.      End;
  87.  
  88.     i     := 1;
  89.     iCount:= 0;
  90.  
  91.     While(i <= 20)
  92.     Do
  93.      Begin
  94.       If (arrScore[i] >= 250)
  95.       Then
  96.        Begin
  97.         iCount:= iCount +1;
  98.         Writeln('Team has reccieved more than 250 points: ', arrTeam[i]);
  99.        End;
  100.       i:= i +1;
  101.      End;
  102.  
  103.     Writeln();
  104.     Writeln('The total amount of teams that recieved more than 250 points is: ', iCount);
  105.     Readln();
  106.    End;
  107.  
  108. END.                              
  109.  
« Last Edit: October 31, 2016, 08:11:24 pm by SoE »

Bart

  • Hero Member
  • *****
  • Posts: 5713
    • Bart en Mariska's Webstek
Re: program help
« Reply #9 on: October 31, 2016, 10:39:27 pm »
What did I win ???

Nothing.
TS will be glad now he has no more work to do.

Bart

RAW

  • Hero Member
  • *****
  • Posts: 871
Re: program help
« Reply #10 on: November 01, 2016, 01:00:29 am »
Hi Bart,

I think you miss the mark... the work needs to be done inside his head !
What good is a source-code downloaded from the internet if you don't understand what is going on?

Right! It won't help you...

I had a lot of fun  :)
I normally don't do console apps...
I don't even know how to prevent the typing of an invalid number (ReadLn) without Try_Except_End...??

I mean if you for example write "j" instead of "2" then immediately the program shows an Exception "RunError (106)".
That's funny...  :D

Normally I use a TEdit and I know how to prevent this... with or without Try_Except_End...

I don't understand why they teach such console apps... I've never ever found such an app in any company, but I've seen a lot of bad GUI's...  :)
Maybe they are of interest in relation to other topics, but like this it's nonsense to me...

Thaddy

  • Hero Member
  • *****
  • Posts: 18951
  • Glad to be alive.
Re: program help
« Reply #11 on: November 01, 2016, 10:01:46 am »
https://en.wikipedia.org/wiki/Pseudocode

The teacher is right, Bart converted it to code.... :-X :-[
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.

Bart

  • Hero Member
  • *****
  • Posts: 5713
    • Bart en Mariska's Webstek
Re: program help
« Reply #12 on: November 01, 2016, 02:34:55 pm »
The teacher is right, Bart converted it to code.... :-X :-[

I did not write any code at all  >:D
(I merely re-posted it inside code-tags and with proper indentation)

Bart

Bart

  • Hero Member
  • *****
  • Posts: 5713
    • Bart en Mariska's Webstek
Re: program help
« Reply #13 on: November 01, 2016, 02:41:23 pm »
I don't even know how to prevent the typing of an invalid number (ReadLn) without Try_Except_End...??

You do not read it as a number, just read anything as a string and then convert after reading.

Code: [Select]
var
  S: String;
  Num: Integer;
  F: TextFile;
begin
  Readln(F, S);
  if not TryStrToInt(S, Num) then
    writeln(S,' is not a valid number.');
end.

Unfortunately even in TryStrToInt an exception can occur if S holds a number, but the number causes a range-check error (i.e. if S = '9999999999999999999999999999999999'), so you either protect yourself agains this using try..except or you truncate the string to a size where you know it will fit, and convert after that.

Bart

RAW

  • Hero Member
  • *****
  • Posts: 871
Re: program help
« Reply #14 on: November 02, 2016, 01:35:47 am »
I SEE.... said the blind man...

Code: Pascal  [Select][+][-]
  1. PROGRAM ValidNumber;
  2.   {$APPTYPE CONSOLE} // LAZARUS-IDE
  3.  USES
  4.   Crt, SysUtils;
  5.  
  6.  VAR
  7.   strNum: String[5];
  8.   iNum  : Integer;
  9.   booOK : Boolean;
  10.  
  11. BEGIN
  12.  booOK:= False;
  13.  
  14.   While Not booOK
  15.   Do
  16.    Begin
  17.     ClrScr;
  18.     WriteLn('Input a number: ');
  19.     ReadLn (strNum);
  20.  
  21.     If Not TryStrToInt(strNum, iNum)
  22.     Then
  23.      Begin
  24.       ClrScr;
  25.       WriteLn(strNum,' is not a valid number...  '+
  26.               sLineBreak+
  27.               sLineBreak+'Press <Enter> to try again...');
  28.      End
  29.     Else
  30.      Begin
  31.       WriteLn();
  32.       WriteLn('Yes, '+strNum+' is a valid number...');
  33.       booOK:= True;
  34.      End;
  35.     ReadLn();
  36.    End;
  37. END.        
  38.  

Thank you very much Bart....

 

TinyPortal © 2005-2018