I cannot get this to run correctly no matter what I do...
//Program 2
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
int die1;
int die2;
int sum;
int point;
char play;
int played;
int won;
int lost;
played = 0;
won = 0;
lost = 0;
srand( time(NULL) );
do
{
point = 0;
sum = 0;
die1 = rand() % 6 + 1;
die2 = rand() % 6 + 1;
sum = die1 + die2;
cout << "die1 = " << die1 << " and die2 = " << die2 << endl;
cout << "sum = " << sum << endl;
if (sum == 7 || sum == 11)
{
cout << "Congratulations. You win!" << endl;
won++;
}
if (sum == 2)
{
cout << "Sorry. You lose." << endl;
lost++;
}
else
{
point = sum;
cout << "Your point is: " << sum << endl;
cout << "Press ENTER to roll again." << endl;
cin.get();
do
{
die1 = rand() % 6 + 1;
die2 = rand() % 6 + 1;
sum = die1 + die2;
cout << "die1 = " << die1 << " and die2 = " << die2 << endl;
cout << "sum = " << sum << endl;
if(sum == point)
{
cout << "Congratulations. You win!" << endl;
won++;
}
if (sum == 7)
{
cout << "Sorry. You lose." << endl;
lost++;
}
else
{
die1 = rand() % 6 + 1;
die2 = rand() % 6 + 1;
sum = die1 + die2;
cout << "die1 = " << die1 << " and die2 = " << die2 << endl;
cout << "sum = " << sum << endl;
}
}while(sum != point);
cout << "Congratulations. You win!" << endl;
won++;
}
played++;
cout << "Play again? Y/N" << endl;
cin >> play;
} while(play == 'Y');
//***********************************************************************************
//*****************************************************
cout << "Total games played: " << played << endl;
cout << "Total games won: " << won << endl;
cout << "Total games lost: " << lost << endl;
return 0;
}
#include <cstdlib>
at the top of your page will help a bit.