

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Homework Assignment 4 Due Thursday, November 15, 2007, at 10pm.
While you may discuss this assignment with others, all work you submit must be your own. That means, after discussing it, you must go back and write it up yourself.
Software Development Process:
Part I:
The software development steps are specified in the assignment, so for this one time, you do not need to submit a development process page. However, your program should be thoroughly commented.
Part II:
Follow the above steps to write a C program for the following problem.
Program Description
For this problem, you are going to write a program that plays a game for two people that we will call “dice war”. This game is similar to one that is often played by children with a deck of cards and called “war”, but in this version, each player will roll a die to get their next number.
The game will be played for 8 rounds, where each player gets a number by a roll of the dice. In any one round, if there is a tie, i.e. if the players roll the same number, then the dice must be rolled again to get two new numbers. In fact, as long as there is a tie, the dice will be rolled again.
After the players have rolled the dice for 8 rounds, then the rounds are scored. Each player will receive a score that is the sum of their scores for the rounds. In each round, the player with the highest of the two numbers from the dice will get the sum of the numbers. The player with the highest score from the 8 rounds will win.
Program Analysis
This program has no inputs from the user. (Note: like the children’s game “war”, there is no skill involved to play this game!)
The outputs will be printouts showing the state of the game as it progresses. For each round, the program will print the numbers of the rolls of the dice. If there is a tie in a round, it will show the numbers from rolling the dice again. (Note: I think that in the children’s game, if you have a tie, it is called a war.) After all 8 rounds of play, then the score is computed, and printed out. A message stating whether the final scores show a tie or a win for one of the players should be printed.
The output should look something like:
Welcome to the game of dice war. There will be 8 rounds of play.
Player 1 rolled 1, Player 2 rolled 4 Player 1 rolled 5, Player 2 rolled 2 Player 1 rolled 6, Player 2 rolled 3 Player 1 rolled 1, Player 2 rolled 1 War! Player 1 rolled 2, Player 2 rolled 4 Player 1 rolled 2, Player 2 rolled 4 Player 1 rolled 1, Player 2 rolled 2 Player 1 rolled 3, Player 2 rolled 3 War! Player 1 rolled 5, Player 2 rolled 5 War! Player 1 rolled 3, Player 2 rolled 1 Player 1 rolled 3, Player 2 rolled 1
Player 1 scored 24, Player 2 scored 20
Player 1 wins!
Other variables. Here is a description of the variables, and I leave it up to you to pick out names:
Program Steps
Functions: Use “srand( )” from stdlib.h and “time(0)” from time.h to generate a random seed for the random number generator.