-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsw_Lab4.m
More file actions
31 lines (31 loc) · 840 Bytes
/
csw_Lab4.m
File metadata and controls
31 lines (31 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
%Game of Pig
clc;clear;
totalpts=0;
turn=0;
while totalpts<100
turn=turn+1;
turnpts=0;
fprintf('Turn %g with %g points:\n',turn,totalpts)
while true
roll=randi([1 6]);
fprintf('Roll: %g ',roll)
if roll==1
turnpts=0;
fprintf('Pig! You lose all points for this round...\n\n')
break;
else
turnpts=turnpts+roll;
if turnpts+totalpts>=100
totalpts=turnpts+totalpts;
break;
end
rollagain = input('Roll again? (y/n): ','s');
if rollagain=='n'
totalpts=totalpts+turnpts;
fprintf('\n')
break;
end
end
end
end
fprintf('\nIt took you %g turns to get to 100 points!',turn)