what error appears , compile error or logical
i have compiled the next code and i think it works
if the problem does not have to do with compile then please tell us what make you think its wrong
what i noticed is that the while keep looping even if the user says n because of this
Code:
while ((again == 'y') || (again == 'n'));
i think you meant this
Code:
while ((again == 'y')
also this
Code:
{
dice1 = 1 + rand() % 6;
dice2 = 1 + rand() % 6;
cout << dice1 << " " << dice2 << " " << endl <<
endl;
tod = dice1 + dice2;
cout << "The total of the dice is " << tod << endl <<
endl;
cout << "Bet rides, ROLL AGAIN (press 'y') \n\n";
}
always run because its not inside of any if
Code:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
using namespace std;
int main()
{
int betAmount;
string answer;
cout << "*** Welcome to HIGH ROLLER Craps *** \n"; // Telling the user what the program is.
cout << "________________________________________\n";
cout << "Ladies and Gentlemen....Place your bets! \n\n";
cin >> betAmount;
cout << "\n You bet $" << betAmount << ". \n\n";
int dice1, dice2;
dice1 = rand(); // These are the random dice rolls.
dice2 = rand();
unsigned seed; // Random generator seed.
seed = time(0);
srand(seed); // Initialize random seed.
char again; // Loop again? Yes or no?
do
{
dice1 = 1 + rand() % 6; // This generates a random number for dice 1
dice2 = 1 + rand() % 6; // This generates a random number for dice 2
cout << dice1 << " " << dice2 << " " << endl << endl;
double tod = dice1 + dice2; // This is total of the dice
cout << "The total of the dice is " << tod << endl << endl;
{
double pointTod = tod;
if (tod == 2 || tod == 3 || tod == 12)
{
cout << "You LOST $" << betAmount << endl << endl;
cout << " Want to play again? (Y/N) \n\n";
cin >> again;
}
else if (tod == 7 || tod == 11)
{
cout << "You WON $" << betAmount * 2 << endl << endl;
cout << " Want to play again? (Y/N) \n\n";
cin >> again;
}
else if (tod == 4 || tod == 5 || tod == 6 || tod == 8 || tod
== 9 || tod == 10)
{
cout << "Bet rides, your point is " << tod << "*ROLL AGAIN* (press 'y') \n\n";
cin >> again;
}
{
dice1 = 1 + rand() % 6;
dice2 = 1 + rand() % 6;
cout << dice1 << " " << dice2 << " " << endl <<
endl;
tod = dice1 + dice2;
cout << "The total of the dice is " << tod << endl <<
endl;
cout << "Bet rides, ROLL AGAIN (press 'y') \n\n";
}
{if (pointTod)
{
cout << "The total of the dice is " << pointTod <<
endl << endl;
cout << "You won!!!\n\n";
cin >> again;
}
else if (tod == 7 || tod == 11)
{
cout << "You lose!\n\n";
cout << " Want to play again? (Y/N) \n\n";
cin >> again;
}
else if (tod == 2 || tod == 3 || tod == 4 || tod == 5 ||
tod == 6 || tod == 8 || tod == 9 || tod == 10 ||
tod == 12)
{
cout << "Bet rides, ROLL AGAIN (press 'y') \n\n";
cin >> again;
dice1 = 1 + rand() % 6;
dice2 = 1 + rand() % 6;
cout << dice1 << " " << dice2 << " " << endl
<< endl;
tod = dice1 + dice2;
cout << "The total of the dice is " << tod << endl
<< endl;
}
}
}
}
while ((again == 'y') || (again == 'n'));
system("pause");
}