Ok here is what needs to be done.
• Create a do loop that asks the user if they want to roll the dice (yes or no) until the user says no.
• At the beginning of the loop ask the user how many sides the dice has (either 4, 6, 8, 10, 12, or 20).
• Use the rand() function and output the statement "You rolled a " and then a random number that can be found on the type of dice they chose. So a 6 sided dice can give the number 1 through 6.
• Use a switch statement to check the user input for the sides of dice. There should be 6 case statements (1 for each type of dice).
• Just before the program exits print out an exit statement.
I dont know if Im doing it right or if I understand what he is looking for in the switch statements. I am so lost didnt help I dont have the class book yet. Dam book store. any help is greatly appreciated!
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <iostream>
#include <ctime>
using namespace std;
int throwDie(int Sides, int &throwResult)
{
throwResult = 1 + rand() % (Sides - 1 + 1);
return throwResult;
}
int main()
{
int dieTot = 0,
throwNumber = 0,
numberSides = 0,
throwResult = 0;
char rollAgain;
srand(unsigned(time(0) ));
cout << "Do you want to throw a die?" << endl;
cin >> rollAgain;
do{
cout << "How many sides? 4, 6, 8, 10, 12, 20" << endl;
cin >> numberSides;
cout << numberSides << "-sided die rolled for a value of " << throwDie(numberSides, throwResult) << "!" << endl;
dieTot = dieTot + throwResult;
throwNumber++;
cout << "Do you want to throw a die?" << endl;
cin >> rollAgain;
}while(toupper(rollAgain) == 'Y');
switch( numberSides )
{
case 1:
cout << "You have choosen a 4 sided die? ";
cin >> numberSides;
break;
case 2:
cout << "You Choosen a 6 sided die? ";
cin >> numberSides;
break;
case 3:
cout << "You Choosen a 8 sided die? ";
cin >> numberSides;
break;
case 4:
cout << "You Choosen a 10 sided die? ";
cin >> numberSides;
break;
case 5:
cout << "You Choosen a 12 sided die? ";
cin >> numberSides;
break;
case 6:
cout << "You Choosen a 20 sided die? ";
cin >> numberSides;
break;
default:
cout << "Not a proper entry.\n";
break;
cout << endl << "Total for " << throwNumber << " throws = " << dieTot << endl;
return 0;
}
}
|