Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Pascal: Bowling output problem

agurchikagurchik Member Posts: 2
program bowling; {the name of the program} uses crt; {} {2/2/05} {2.2.2} {this program bowls} type bowlscore=record b1,b2:integer; score:integer; total:integer; end; var bray:array[1..11] of bowlscore; {data storage} datafile,outfile:text; score1,score2,total:integer; framenum:integer; cs:integer; begin assign(outfile,'C: ight.txt'); {tells the program where to outfile} rewrite(outfile); assign(datafile,'C:owl.txt'); {tells the program where to get the data} reset(datafile); writeln(outfile,''); cs:=0; for framenum:= 1 to 11 do {reads data into the array of records} begin readln(datafile,score1,score2); bray[framenum].b1:=score1; {sets b1 equal to score1} bray[framenum].b2:=score2; {sets b2 equal to score2} total:=score1 + score2; if (bray[framenum].b1<>10) and (total <> 10) then { not strike or spare} if framenum = 1 then bray[framenum].score:=(bray[framenum].b1)+(bray[framenum].b2) else bray[framenum].score:=(bray[framenum - 1].score)+ total else {when it is a spare} if (framenum<>10) and ((bray[framenum].b1+bray[framenum].b2)=10) then begin bray[framenum].score:=(bray[framenum].b1+bray[framenum].b2)+(bray[framenum+1].b1)+ (bray[framenum-1].score); end; if (framenum<>10) and (bray[framenum].b1=10) then begin bray[framenum].score:=(bray[framenum].b1+bray[framenum].b2)+(bray[framenum+1].b1+bray[framenum+1].b2); bray[framenum].total:=bray[framenum].total+bray[framenum].score; writeln(outfile,'First ball ',(bray[framenum].b1)); writeln(outfile,'Second ball ',(bray[framenum].b2)); writeln(outfile,'Frame Score ',bray[framenum].score); writeln(outfile,'Total Score ',bray[framenum].total); writeln(outfile,''); end; end; close(datafile); close(outfile); readln; end. {ends program}


I'm having problems with output. My teacher said to put output in loop at end of program but didn't tell me exactly how. For some reason the output comes out wrong in text. Am I doing something wrong?

Comments

  • DrMartenDrMarten Member Posts: 748

    Yes it appears so from 1st glancing at these WRITELN statements.
    From what I have seen in bowling alleys the score for each player is listed on a separate horizontal line so you could use a WRITELN command one in a loop for each player like this:->

    WriteLn ( 1stBall,2ndBall,Frame1Score,3rdBall,4thBall,Frame2Score,5thBall,6thBall,Frame3Score,7thBall,8thBall,Frame4Score,9thBall,10thBall,Frame5Score,11thBall,12thBall,Frame6Score,13thBall,14thBall,Frame7Score,15thBall,16thBall,Frame8Score,17thBall,18thBall,Frame9Score,19thBall,20thBall,Frame10Score,21stBall,FinalScore);

    Using an array for each variable up to the number of players in the game.

    The problem here is that a WRITELN command inserts a LF/CR ( line feed and carriage return character ) either immediately or as soon as another WRITELN is encountered. Meaning in simple terms that a new line is "printed".

    If I remember PASCAL correctly another way around this problem would be to do the following using your variables, the WRITE command does not make the output for each detail for each player start on a new line:->

    : if (framenum<>10) and (bray[framenum].b1=10) then
    : begin
    : bray[framenum].score:=(bray[framenum].b1+bray[framenum].b2)+(bray[framenum+1].b1+bray[framenum+1].b2);
    : bray[framenum].total:=bray[framenum].total+bray[framenum].score;
    : write(outfile,'First ball ',(bray[framenum].b1));
    : write(outfile,'Second ball ',(bray[framenum].b2));
    : write(outfile,'Frame Score ',bray[framenum].score);
    : write(outfile,'Total Score ',bray[framenum].total);
    : writeln(outfile,'');
    : end;

    Don't forget that a "SPARE" in the last frame gives you one more go or a 21st ball.
    Hope this helps. :-)

  • agurchikagurchik Member Posts: 2
    Thanks DrMarten!
  • DrMartenDrMarten Member Posts: 748
    : Thanks DrMarten!
    :
    No problem. :-)

Sign In or Register to comment.