Okay so almost everytime I make a program that input's a number, if I type a letter it will mess up the program.
Is their a way to deny all leters and symbols except numbers?
Here is the source.
/* Twenty-One
Chris Mayhew */
#include <iostream.h>
#include <string.h>
#include <h:\lvp\random.h>
int main()
{
randomize();
int howmanytheywant;
int totalcomputer = 0;
int totalhuman = 0;
int valuecomputer;
int valuehuman;
int humanwin = 0;
int computerwin = 0;
int drawwin = 0;
char Answer;
do {
totalcomputer = 0;
totalhuman = 0;
cout << "How many cards do you want? ";
cin >> howmanytheywant;
if (howmanytheywant > 22) {
cout << "Please enter a lower number: ";
cin >> howmanytheywant;
}
cout << "You: ";
for (int cardamount=1; cardamount<=howmanytheywant; cardamount++) {
valuehuman = random(10)+1;
cout << valuehuman << " ";
totalhuman = valuehuman+totalhuman;
}
cout << endl;
cout << "Computer: ";
for (int computercard=1; computercard<=3; computercard++) {
valuecomputer = random(10)+1;
cout << valuecomputer << " ";
totalcomputer = valuecomputer+totalcomputer;
}
cout << endl;
cout << "I have " << totalcomputer << " and you have " << totalhuman;
if ((totalcomputer > totalhuman) && ((totalhuman <= 21) && (totalcomputer <= 21))) {
cout << " so I win";
computerwin++;
}
if ((totalcomputer < totalhuman) && ((totalhuman <= 21) && (totalcomputer <= 21))) {
cout << " so you win";
humanwin++;
}
if ((totalhuman >=22) && (totalcomputer <=21)) {
cout << " so I win";
computerwin++;
}
if ((totalcomputer >=22) && (totalhuman <=21)) {
cout << " so you win";
humanwin++;
}
if (totalcomputer == totalhuman) {
cout << " so we draw";
drawwin++;
}
cout << endl;
cout << "Would you like to play again (Y/N)?";
cin >> Answer;
cout << endl;
} while ((Answer == 'Y') || (Answer == 'y'));
cout << "Computer Wins = " << computerwin << endl;
cout << "Human Wins = " << humanwin << endl;
cout << "Draws = " << drawwin << endl;
return(0);
}
Is their a way to deny all leters and symbols except numbers?
Here is the source.
/* Twenty-One
Chris Mayhew */
#include <iostream.h>
#include <string.h>
#include <h:\lvp\random.h>
int main()
{
randomize();
int howmanytheywant;
int totalcomputer = 0;
int totalhuman = 0;
int valuecomputer;
int valuehuman;
int humanwin = 0;
int computerwin = 0;
int drawwin = 0;
char Answer;
do {
totalcomputer = 0;
totalhuman = 0;
cout << "How many cards do you want? ";
cin >> howmanytheywant;
if (howmanytheywant > 22) {
cout << "Please enter a lower number: ";
cin >> howmanytheywant;
}
cout << "You: ";
for (int cardamount=1; cardamount<=howmanytheywant; cardamount++) {
valuehuman = random(10)+1;
cout << valuehuman << " ";
totalhuman = valuehuman+totalhuman;
}
cout << endl;
cout << "Computer: ";
for (int computercard=1; computercard<=3; computercard++) {
valuecomputer = random(10)+1;
cout << valuecomputer << " ";
totalcomputer = valuecomputer+totalcomputer;
}
cout << endl;
cout << "I have " << totalcomputer << " and you have " << totalhuman;
if ((totalcomputer > totalhuman) && ((totalhuman <= 21) && (totalcomputer <= 21))) {
cout << " so I win";
computerwin++;
}
if ((totalcomputer < totalhuman) && ((totalhuman <= 21) && (totalcomputer <= 21))) {
cout << " so you win";
humanwin++;
}
if ((totalhuman >=22) && (totalcomputer <=21)) {
cout << " so I win";
computerwin++;
}
if ((totalcomputer >=22) && (totalhuman <=21)) {
cout << " so you win";
humanwin++;
}
if (totalcomputer == totalhuman) {
cout << " so we draw";
drawwin++;
}
cout << endl;
cout << "Would you like to play again (Y/N)?";
cin >> Answer;
cout << endl;
} while ((Answer == 'Y') || (Answer == 'y'));
cout << "Computer Wins = " << computerwin << endl;
cout << "Human Wins = " << humanwin << endl;
cout << "Draws = " << drawwin << endl;
return(0);
}