Recklein3
10-22-2009, 10:24 AM
Trying to write a program in C++ to play craps.
But I have one little problem left.
I can't get it to exit when you press n, just continue when you press y.
I've tried a few ways, but none seem to get both to work at the same time.
Help would great.
Thanks!
#include <iostream>
using namespace std;
#include <stdlib.h>
#include <time.h>
#include "CrapsCal.h"
void main()
{
double cashmoney(50.00);
double bet(0.00);
char timeup(0);
do
{
int point_one(0);
int point_two(0);
char timeup(0);
char srand (time (0));
cout << "Cash in hand: $" << cashmoney << endl;
cout << "Place your bet and roll the dice (maximum bet equals cash in hand): ";
cin >> bet;
if(bet > cashmoney && bet > 0)
{
cout << "Bet is too high, please bet lower or equal to amount of cash on hand: ";
cin >> bet;
}
cashmoney -= bet;
point_one = throwdice();
cout << "Your roll equals: " << point_one << endl;
if(cal1(point_one) == 1)
{
cout << "You Win!" << endl;
cashmoney += (bet*2);
point_one = 0;
bet = 0.00;
cout << "Total cash in hand equals: $" << cashmoney << endl;
}
else if(cal1(point_one) == -1)
{
cout << "You Lost...." << endl;
cashmoney - bet;
point_one = 0;
bet = 0.00;
cout << "Total cash in hand equals: $" << cashmoney << endl;
}
else
{
do
{
point_two = throwdice();
cout << "New roll equals: "<< point_two << endl;
cout << "Old Point equals: "<< point_one << endl;
cout << "New Point equals: "<< point_two << endl;
if(cal2(point_one , point_two) == 1)
{
cout << "You Win!" << endl;
cashmoney += (bet*2);
point_one = 0;
bet = 0.00;
cout << "Total cash in hand equals: $" << cashmoney << endl;
}
else if(cal2(point_one , point_two) == -1)
{
cout << "You Lost...." << endl;
cashmoney - bet;
point_one = 0;
bet = 0.00;
cout << "Total cash in hand equals: $" << cashmoney << endl;
}
}
while(cal2(point_one , point_two) != 1 && cal2(point_one , point_two) != -1);
}
cout << "Would you like to test your luck again? (y/n) ";
cin >> timeup;
}
while((timeup != 'y') || (timeup != 'Y') && (timeup == 'n') || (timeup == 'N'));
{
if ((timeup == 'n') || (timeup == 'N'));
exit (0);
}
But I have one little problem left.
I can't get it to exit when you press n, just continue when you press y.
I've tried a few ways, but none seem to get both to work at the same time.
Help would great.
Thanks!
#include <iostream>
using namespace std;
#include <stdlib.h>
#include <time.h>
#include "CrapsCal.h"
void main()
{
double cashmoney(50.00);
double bet(0.00);
char timeup(0);
do
{
int point_one(0);
int point_two(0);
char timeup(0);
char srand (time (0));
cout << "Cash in hand: $" << cashmoney << endl;
cout << "Place your bet and roll the dice (maximum bet equals cash in hand): ";
cin >> bet;
if(bet > cashmoney && bet > 0)
{
cout << "Bet is too high, please bet lower or equal to amount of cash on hand: ";
cin >> bet;
}
cashmoney -= bet;
point_one = throwdice();
cout << "Your roll equals: " << point_one << endl;
if(cal1(point_one) == 1)
{
cout << "You Win!" << endl;
cashmoney += (bet*2);
point_one = 0;
bet = 0.00;
cout << "Total cash in hand equals: $" << cashmoney << endl;
}
else if(cal1(point_one) == -1)
{
cout << "You Lost...." << endl;
cashmoney - bet;
point_one = 0;
bet = 0.00;
cout << "Total cash in hand equals: $" << cashmoney << endl;
}
else
{
do
{
point_two = throwdice();
cout << "New roll equals: "<< point_two << endl;
cout << "Old Point equals: "<< point_one << endl;
cout << "New Point equals: "<< point_two << endl;
if(cal2(point_one , point_two) == 1)
{
cout << "You Win!" << endl;
cashmoney += (bet*2);
point_one = 0;
bet = 0.00;
cout << "Total cash in hand equals: $" << cashmoney << endl;
}
else if(cal2(point_one , point_two) == -1)
{
cout << "You Lost...." << endl;
cashmoney - bet;
point_one = 0;
bet = 0.00;
cout << "Total cash in hand equals: $" << cashmoney << endl;
}
}
while(cal2(point_one , point_two) != 1 && cal2(point_one , point_two) != -1);
}
cout << "Would you like to test your luck again? (y/n) ";
cin >> timeup;
}
while((timeup != 'y') || (timeup != 'Y') && (timeup == 'n') || (timeup == 'N'));
{
if ((timeup == 'n') || (timeup == 'N'));
exit (0);
}