#include <iostream> #include <cstdlib> using namespace std; int main() { int card = rand() % 52; switch (card % 13) { case 0: cout << "two"; break; case 1: cout << "three"; break; case 2: cout << "four"; break; case 3: cout << "five"; break; case 4: cout << "six"; break; case 5: cout << "seven"; break; case 6: cout << "eight"; break; case 7: cout << "nine"; break; case 8: cout << "ten"; break; case 9: cout << "jack"; break; case 10: cout << "queen"; break; case 11: cout << "king"; break; case 12: cout << "ace"; break; default: ; } cout << " of "; switch (card / 13) { case 0: cout << "clubs"; break; case 1: cout << "diamonds"; break; case 2: cout << "hearts"; break; case 3: cout << "spades"; break; default: ; } cout << endl; } |
Practice Exercise 5 Email only the source code for each practice exercise as an email attachment. There is no due date. Use "Practice Exercise 5" as the email subject. Add (a) comment(s) at the top of your program with your name, practice exercise 5, your compiler and operating system. Write a program in which you simulate a simply dice game. The game consists of rolling two dice and adding the sum of the dice to a total. The game continues until the total reaches 100 or more. Your solution should include a roll function that displays the result of each roll and returns the sum. If the sum of the two rolls is 7, then the function returns 0 and the total is reset to 0. Your output should look similar to the following:
|