I have written a program that ask user the total amount of winning and losing hands in poker and then gives back his or her percentages.
But I am having trouble with the do while loop. I am trying to get the do while loop to verify that the users only inputs numbers and if not then it should prompt the user again.
The program works when you just put in numbers but it gives this output when you put in ANYthing else:
**************************************************
Note: The below stats could be for one continuous session of poker or for entire
lifetime.
Heads up, if you enter anything but a number you will be prompted to reenter.
Please enter in the total number of hands the DEALER dealt: dfsa
Please enter the total number of poker hands you got involved in preflop:
Please enter the number of hands you have LOST:
Please enter the number of hands you have WON:
Total percentage of hands won out of 1.6978e-313 hands = 1.#INF
Total percentage of hands lost out of 1.6978e-313 hands = 311237
Press any key to continue . . .
**************************************************
Here is my code:
Code:
//Gordon Campbell Sept 2 2013
//creating a program that uses a function to calculate poker win/loss percentages
//I am having trouble with the do wile loop and the function it calls ie "notnumber" function
//trying to get the notnumber function in the do while loop to check the user input for characters,
//if user inputs anything but numbers it should prompt user to reenter correct input :(
#include <iostream>
using namespace std;
double averageloss (double loss, double totalhands); //prototype for average losses
double averagewin (double win, double totalhands); //prototype for average wins
char notnumber (char alpha); //prototype for do while loop to verify user input is a number
int main()
{
char alpha; //variable used in do while loop and function
double loss; //variable used for hands lost
double win; //variable used for hands won
double involvedhands; //variable representing total hands usder got involved in preflop
double totaldealt; //wariable used for total hands DEALER dealt
cout<<"Note: The below stats could be for one continuous session of poker or for entire lifetime."<<endl;
cout<<"Heads up, through out this program, if you enter anything but a number you will be prompted to reenter."<<endl;
do //supposed to check if user input is non alpha characters, but it does not work... boo
{
cout<<"Please enter in the total number of hands the DEALER dealt: ";
cin>>totaldealt;
cout<<" "<<endl; //use to produce a visual space before next cout statement
}while(totaldealt == notnumber (alpha));
cout<<"Please enter the total number of poker hands you got involved in preflop: ";
cin>>involvedhands;
cout<<" "<<endl; //use to produce a visual space before next line
cout<<"Please enter the number of hands you have LOST: ";
cin>>loss; //passed into the averageloss function
cout<<" "<<endl; //use to produce a visual space before next line
cout<<"Please enter the number of hands you have WON: ";
cin>>win; //passed into the averagewin function
cout<<" "<<endl; //use to produce a visual space before next line
cout<<"Total percentage of hands won out of "<<involvedhands<<" hands = "<<averagewin(win, involvedhands) <<"\n"<<endl;
cout<<"Total percentage of hands lost out of "<<involvedhands<<" hands = "<<averageloss(loss, involvedhands) <<"\n"<<endl;
system("PAUSE");
}
double averagewin(double win, double involvedhands) //function definition for average wins
{
return win / involvedhands;
}
double averageloss(double loss, double involvedhands) //function definition for average losses
{
return loss / involvedhands;
}
char notnumber(char alpha) //function definition called in do while loop
{
alpha >= 'A' && alpha <= 'Z';
return alpha;
}
How do I write a loop that checks for correct numeric user input?
It doesn't have to be a do while loop...
I would appreciate any help in this manner.
Thanks again,
Gordon
</code>