Thanks you guys. After a little bit of experimenting with it, I was able to get it to do what I wanted.
Now what do I need to switch if I want it to only read chars and not integers?
EDIT: Well, I thought it worked. It works in the sense that it solves my input only numbers problem. But now, it won't show my errors for when the user inputs more than they have or less than a dollar.
Here's the source for the bet() function:
Code:
void bet() // bet() function
{
do { // start of Do While loop
clrscrn(); // Clears the screen
SetConsoleTextAttribute(hOut, FBI); // Sets the text color to bright blue
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; // ASCII graphics
cout<<"~~~~~~~~~ "; // Ascii graphics
SetConsoleTextAttribute(hOut, FWI); // Sets the text color to bright white
cout<<"How much would you like to bet? ";
SetConsoleTextAttribute(hOut, FBI); // Sets the text color to bright blue
cout<<"~~~~~~~~\n"; //
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; //
cout<<"~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; // Rest of ASCII graphics
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~\n"; //
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; //
Position.X = 4;
Position.Y = 3;
SetConsoleCursorPosition(hOut, Position);
SetConsoleTextAttribute(hOut, FGI);
cout<<"Money: $"<< money;
Position.X = 33;
Position.Y = 4;
SetConsoleCursorPosition(hOut, Position);
cout<<"Bet: $";
while (!(std::cin >> amountbet))
{
// reset the status of the stream
std::cin.clear();
// ignore remaining characters in the stream
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
Position.X = 0;
Position.Y = 6;
SetConsoleTextAttribute(hOut, FRI);
SetConsoleCursorPosition(hOut, Position);
std::cout << "\aYou must enter a number.\n";
Position.X = 39;
Position.Y = 4;
SetConsoleCursorPosition(hOut, Position);
cout<<" ";
SetConsoleCursorPosition(hOut, Position);
SetConsoleTextAttribute(hOut, FGI);
}
Position.X = 0;
Position.Y = 6;
SetConsoleCursorPosition(hOut, Position);
if ( amountbet > 0 && amountbet <= money )
{
betloop1 = 1;
}
else if ( amountbet <=0 )
{
betloop1 = 0;
SetConsoleTextAttribute(hOut, FRI);
cout<<"!!!!!!!!!! You must bet at least $0.01 !!!!!!!!!!!\n\n";
cout<<"Press enter to try again.\n";
cin.get();
}
else if ( amountbet > money )
{
betloop1 = 0;
SetConsoleTextAttribute(hOut, FRI);
cout<<"!!!!!!!!!! You don't have enough money !!!!!!!!!!!\n\n";
cout<<"Press enter to try again.\n";
cin.get();
}
else
{
error();
}
} while ( betloop1 !=1 );
do {
clrscrn();
SetConsoleTextAttribute(hOut, FBI);
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<<"~~~~~~~~~~ ";
SetConsoleTextAttribute(hOut, FWI);
cout<<"What number (2-12) to bet on";
SetConsoleTextAttribute(hOut, FBI);
cout<<" ~~~~~~~~~~\n";
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<<"~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
Position.X = 4;
Position.Y = 3;
SetConsoleCursorPosition(hOut, Position);
SetConsoleTextAttribute(hOut, FCI);
cout<<"Number to bet on: ";
while (!(std::cin >> numberbet))
{
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
Position.X = 0;
Position.Y = 5;
SetConsoleCursorPosition(hOut, Position);
SetConsoleTextAttribute(hOut, FRI);
std::cout<<"\aYou must enter a number.\n";
std::cout<<"Please try again.";
Position.X = 22;
Position.Y = 3;
SetConsoleCursorPosition(hOut, Position);
std::cout<<" ";
SetConsoleCursorPosition(hOut, Position);
SetConsoleTextAttribute(hOut, FCI);
}
Position.X = 0;
Position.Y = 5;
SetConsoleCursorPosition(hOut, Position);
if ( numberbet >= 2 && numberbet <= 12 )
{
betloop2 = 1;
}
else if ( numberbet < 2 || numberbet > 12 )
{
betloop2 = 0;
SetConsoleTextAttribute(hOut, FRI);
cout<<"!!!!!!!!!!!! You can only choose 2-12 !!!!!!!!!!!!\n\n";
cout<<"Press enter to try again.\n";
cin.get();
}
else
{
error();
}
} while ( betloop2 != 1 );
}
The compiled program is attached for those who want to see what I'm talking about. Just change the .cpp extension to .zip and unzip it like normal. (compiled on WinXP using Borland compiler).