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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
#include <iostream>
#include<cstdlib>
#include<fstream>
#include "random.cpp"
using namespace std;
int main()
{
ofstream outs;
int diceThrow1, diceThrow2, diceThrow3;
double seed;
int random(double seed);
//Describe the program to the user
cout<<"This program will roll three dice. Based on the outcome\n";
cout<<"of each roll, the user will win or lose a certain amount of money.\n";
cout<<"The rules state, if the user rolls and all three dice are sixes, the\n";
cout<<"user wins $50.00. If the user rolls and two dice are similar, except for\n";
cout<<"the third dice, the user wins $5.00. If the user rolls\n";
cout<<"and all three dice have similar numbers(but not sixes), the user wins\n";
cout<<"$20.00. Lastly, if the user rolls and none of the dice are\n";
cout<<"similar, the user will lose $5.00. Let us begin!\n\n\n\n";
//Prompt the user to enter either the a value between 0 and 1 to
//simulate the first roll of the dice
cout<<"Enter a value between 0 and 1 to simulate the first dice roll:\n";
cin>>(seed);
diceThrow1= random(seed);
//The following code below allows data to be inputed to the external file
//game_results.txt when using outs.open("game_results.txt",ios::app)
outs.open("game_results.txt",ios::app);
//Prompt the user the first number that appears on the first dice
cout<<"Your first roll came out to a "<<diceThrow1<<".\n\n";
outs<<"Your first roll came out to a "<<diceThrow1<<".\n\n";
//Prompt the user to enter either the a value between 0 and 1 to
//simulate the second roll of the dice
cout<<"Enter a value between 0 and 1 to simulate the second dice roll:\n";
cin>>seed;
diceThrow2= random(seed);
//Prompt the user the first number that appears on the second dice roll
cout<<"Your second roll came out to a "<<diceThrow2<<".\n\n";
outs<<"Your second roll came out to a "<<diceThrow2<<".\n\n";
//Prompt the user to enter either the a value between 0 and 1 to
//simulate the third roll of the dice
cout<<"Enter a value between 0 and 1 to simulate the third dice roll:\n";
cin>>seed;
diceThrow3= random(seed);
//Prompt the user the number that appears on the third dice roll and apply the
//if rules
cout<<"Your third roll came out to a "<<diceThrow3<<".\n\n\n";
outs<<"Your third roll came out to a "<<diceThrow3<<".\n\n\n";
//Present more if statments based off the given rules, as well output the results
{
if ((diceThrow1 == 6 )&& (diceThrow2 == 6) && (diceThrow3 == 6))
outs<<"You let out a boisterous guffaw, for you have rolled all sixes.\n"
<<"You've won $50.00!\n\n";
}
{
if ((diceThrow1 == 6 )&& (diceThrow2 == 6) && (diceThrow3 == 6))
cout<<"You let out a boisterous guffaw, for you have rolled all sixes.\n"
<<"You've won $50.00!\n\n";
}
{
if ((diceThrow1 == 5) && (diceThrow2 == 5) && (diceThrow3 == 5))
outs<<"Your voice resonates through the halls as you celebrate your\n"
<<"utmost glory, you have rolled all fives. You win $20.00!\n\n";
if ((diceThrow1 == 5) && (diceThrow2 == 5) && (diceThrow3 == 5))
cout<<"Your voice resonates through the halls as you celebrate your\n"
<<"utmost glory, you have rolled all fives. You win $20.00!\n\n";
}
{
if ((diceThrow1 == 4) && (diceThrow3 == 4) && (diceThrow2 ==4))
outs<<"Your voice resonates through the halls as you celebrate your\n"
<<"utmost glory, you have rolled all fours. You win $20.00!\n\n";
if ((diceThrow1 == 4) && (diceThrow3 == 4) && (diceThrow2 ==4))
cout<<"Your voice resonates through the halls as you celebrate your\n"
<<"utmost glory, you have rolled all fours. You win $20.00!\n\n";
}
{
if ((diceThrow1 == 3) && (diceThrow2 == 3) && (diceThrow3 ==3))
outs<<"Your voice resonates through the halls as you celebrate your\n"
<<"utmost glory, you have rolled all three's. You win $20.00!\n\n";
if ((diceThrow1 == 3) && (diceThrow2 == 3) && (diceThrow3 ==3))
cout<<"Your voice resonates through the halls as you celebrate your\n"
<<"utmost glory, you have rolled all three's. You win $20.00!\n\n";
}
{
if ((diceThrow1 == 2) && (diceThrow2 == 2) && (diceThrow3 ==2))
outs<<"Your voice resonates through the halls as you celebrate your\n"
<<"utmost glory, you have rolled all two's. You win $20.00!\n\n";
if ((diceThrow1 == 2) && (diceThrow2 == 2) && (diceThrow3 ==2))
cout<<"Your voice resonates through the halls as you celebrate your\n"
<<"utmost glory, you have rolled all two's. You win $20.00!\n\n";
}
{
if ((diceThrow1 == 1) && (diceThrow2 == 1) && (diceThrow3 ==1))
outs<<"Your voice resonates through the halls as you celebrate your\n"
<<"utmost glory, have you rolled all two's. You win $20.00!\n\n";
if ((diceThrow1 == 1) && (diceThrow2 == 1) && (diceThrow3 ==1))
cout<<"Your voice resonates through the halls as you celebrate your\n"
<<"utmost glory, you have rolled all two's. You win $20.00!\n\n";
}
//Present more if statments based off the given rules, as well output the results
{
if ((diceThrow2 == diceThrow3) && (diceThrow1 != diceThrow2) && (diceThrow1 != diceThrow3))
outs<<"Your luck is running out for you have rolled only two the same.\n"
<<"You win a mere $5.00!\n\n";
if ((diceThrow2 == diceThrow3) && (diceThrow1 != diceThrow2) && (diceThrow1 != diceThrow3))
cout<<"Your luck is running out for you have rolled only two the same.\n"
<<"You win a mere $5.00!\n\n";
}
{
if ((diceThrow3 == diceThrow1) && (diceThrow2 != diceThrow3) && (diceThrow2 != diceThrow1))
outs<<"Your luck is running out for you have rolled only two the same.\n"
<<"You win a mere $5.00!\n\n";
if ((diceThrow3 == diceThrow1) && (diceThrow2 != diceThrow3) && (diceThrow2 != diceThrow1))
cout<<"Your luck is running out for you have rolled only two the same.\n"
<<"You win a mere $5.00!\n\n";
}
{
if ((diceThrow1 == diceThrow2) && (diceThrow3 != diceThrow1) && (diceThrow3 != diceThrow2))
outs<<"Your luck is running out for you have rolled only two the same.\n"
<<"You win a mere $5.00!\n\n";
if ((diceThrow1 == diceThrow2) && (diceThrow3 != diceThrow1) && (diceThrow3 != diceThrow2))
cout<<"Your luck is running out for you have rolled only two the same.\n"
<<"You win a mere $5.00!\n\n";
}
//Present the last if statments based off the given rules, as well output the results
{
if((diceThrow1 != diceThrow2) && (diceThrow2!= diceThrow3) && (diceThrow1 != diceThrow3))
outs<<"The program cackles maniacally at you as none of the dice\n"
<<"are similar. You lose your $5.00 bet!\n\n";
if((diceThrow1 != diceThrow2) && (diceThrow2!= diceThrow3) && (diceThrow1 != diceThrow3))
cout<<"The program cackles maniacally at you as none of the dice\n"
<<"are similar. You lose your $5.00 bet!\n\n";
}
//Thank the user for participating in this program
cout<<"\n\nThank you for participating in this dice game...\n\n";
outs<<"\n\nThank you for participating in this dice game...\n\n";
outs.close();
system("PAUSE");
return(0);
}
|