lab4.c - die1 = rand() % (6-1+1)+1; die2 = rand() %...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <stdio.h> #include <stdlib.h> #include <time.h> int rollDice(); int craps(); main() { srand(time(NULL)); int i = 0, wins = 0, input; printf("Enter amount of games you want to play: "); scanf("%d", &input); while (i<input) { if (craps() == 1) wins++; i++; } printf("Percent of games won: %f%\n", (float)wins/input); } int rollDice() { int die1; int die2; int workSum;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: die1 = rand() % (6-1+1)+1; die2 = rand() % (6-1+1)+1; workSum = die1 + die2; return workSum; } int craps() { int sum, point; sum = rollDice(); if (sum == 7 || sum == 11) return 1; else if (sum == 2 || sum == 3 || sum == 12) return 0; point = sum; while (sum != 7) { sum = rollDice(); if (sum == point) return 1; } return 0; }...
View Full Document

Page1 / 2

lab4.c - die1 = rand() % (6-1+1)+1; die2 = rand() %...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online