# hw3 - Sum Frequency Percentage 2 990 2.75 3 2009 5.58 4...

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

Programming Assignment 3 ENGR3, Summer Session B 2006 Due: Monday, August 28 5:00 PM Part A (15 points) Write a program that simulates the rolling of two dice. Prompt the user for the number of times the two dice should be thrown. For each throw, calculate the sum of the values of each die. Since each die can show an integer value from 1 to 6, the sum of the two values will vary from 2 to 12. Tally the number of times each sum appears, and calculate the percentage. Finally, print the results in a tabular format. Your program should include a function (that you write) with the prototype: int dieroll(); that uses the rand() function to generate an integer between 1 and 6. The function should return this integer. Hint: Use an array to tally the results of the die rolls. Similar examples have been presented in class. The name of this program must be dicestat.c Example output: % a.out Enter number of throws: 36000

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Sum Frequency Percentage 2 990 2.75 3 2009 5.58 4 3035 8.43 5 3977 11.05 6 5010 13.92 7 6035 16.76 8 5079 14.11 9 3981 11.06 10 2963 8.23 11 1960 5.44 12 961 2.67 Part B (10 points) Write a program that converts currency from US dollars to Canadian dollars. First prompt the user to enter a conversion rate (eg: 1 USD = 1.116 CAD). Then ask for an initial amount in USD, a final amount and an increment. Then print a table with the converted values over the specified range. Your program must include a function that takes two arguments: an amount in USD and the exchange rate, and returns the converted amount in CAD. Your program must be called currency.c Example output: %a.out Enter exchange rate: 1.116 Enter initial amount: 10 Enter final amount: 100 Enter increment: 10 USD CAD 10.00 11.16 20.00 22.32 30.00 33.48 40.00 44.64 50.00 55.80 60.00 66.96 70.00 78.12 80.00 89.28 90.00 100.44 100.00 111.60...
View Full Document

## This note was uploaded on 08/06/2010 for the course ENGR 3 taught by Professor Ben-yaakov during the Summer '08 term at UCSB.

### Page1 / 2

hw3 - Sum Frequency Percentage 2 990 2.75 3 2009 5.58 4...

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

View Full Document
Ask a homework question - tutors are online