## Pascal

Moderators: None (Apply to moderate this forum)
Number of posts: 14016

This Forum Only

help needed Posted by opium13 on 8 Nov 2004 at 2:55 PM
PROGRAM roll;

USES wincrt;

VAR rollnum, total, N, T: integer;

PROCEDURE setup;
BEGIN
randomize;
gotoxy(30,1);
writeln('R O L L . P A S');
rollnum := 1;
END;

PROCEDURE rolldice;
BEGIN gotoxy(20,5);
writeln('Roll Number');
gotoxy(40,5);
writeln('Roll');
gotoxy(50,5);
writeln('Total');
repeat N := random(6)+1;
gotoxy(20,6);
writeln(rollnum);
gotoxy(40,6);
writeln(N);
gotoxy(50,6);
total := N + total;
writeln(total);
rollnum := rollnum + 1;
until total >= 100;
END;

BEGIN
setup;
rolldice;
END.

** Im not sure why this wont work. I need it to count the number of rolls under roll number. Tell the side of the dice it rolled (1..6) under roll. And add the number of the sides together until > 100 **

Re: help needed Posted by zibadian on 9 Nov 2004 at 12:59 AM
: PROGRAM roll;
:
: USES wincrt;
:
: VAR rollnum, total, N, T: integer;
:
: PROCEDURE setup;
: BEGIN
: randomize;
: gotoxy(30,1);
: writeln('R O L L . P A S');
: rollnum := 1;
: END;
:
: PROCEDURE rolldice;
: BEGIN gotoxy(20,5);
: writeln('Roll Number');
: gotoxy(40,5);
: writeln('Roll');
: gotoxy(50,5);
: writeln('Total');
: repeat N := random(6)+1;
: gotoxy(20,6);
: writeln(rollnum);
: gotoxy(40,6);
: writeln(N);
: gotoxy(50,6);
: total := N + total;
: writeln(total);
: rollnum := rollnum + 1;
: until total >= 100;
: END;
:
: BEGIN
: setup;
: rolldice;
: END.
:
: ** Im not sure why this wont work. I need it to count the number of rolls under roll number. Tell the side of the dice it rolled (1..6) under roll. And add the number of the sides together until > 100 **
:
:
A variable declaration doesn't set the variable to a certain value. This means that at the start of the program, the variable total can have any value within the integer range (about -16000 to 16000). Then the rolled numbers are added to it until it reaches 100.
You should explicitly assign 0 to Total in the setup of your program, the same way you did with the rollnum.
Side Note: Pascal has quite strict guidelines about the formatting of the code, which are designed to make it easier to read and reduce the chance of errors. I would strongly suggest that you look into them and apply them. Also this board features several stylecodes, specificly designed to handle programming code. The instructions are below the input field.

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic