help needed - Programmers Heaven

#### Howdy, Stranger!

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

# help needed

Posts: 1Member
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 **

• Posts: 6,349Member
: 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.