Cin besoin aide

Chubab Messages postés 11 Date d'inscription mardi 6 décembre 2005 Statut Membre Dernière intervention 19 mai 2009 - 16 févr. 2006 à 16:02
bayeto Messages postés 224 Date d'inscription mardi 12 août 2003 Statut Membre Dernière intervention 18 octobre 2010 - 16 févr. 2006 à 21:28
voila je suis en train de créer un programme qui donne les probabilités au hold'em poker...
kan jutilise cin pour une variable char il ne prend que le premier charactere (si jen entre plus quun)...cela me va, mon programme gere ceci (arrive ds le cas de la carte 10)
le probleme est le prochain cin est automatique assigner la valeur 0 dans ce cas...je suis capable de gérer ce probleme...mais jaimerais savoir qcq je pourrais faire pour quil ne fasse pas cela...
MERCI,
CHUBAB

PS: désolez pour le code en anglais....

//poker.cpp
//this programs tells you the possibilities you have to get all kind of hands at hold'em poker
#include
using namespace std;
#include <conio.h>
#include


//function declaration
int getcv(char);
int getct(char);


void main()
{
char cardt; //use to get the type of card before changing it to integer
char cardv; //use to get the card value before changing it to integer
int ct[7]; //variable containing the type of the seven cards (1=Spade, 2=Hearth, 3=Club, 4=Diamond)
int cv[7]; //variable contaning the value of the seven cards (from 2 to ace)

//get the value and type of the first two cards and change it to integer value
cout << "This programs tells you the possibilities you have in hold'em poker as the game goes on!!\n";
cout << "Enter the type of the first card (S,H,C,D):";
cin >>cardt;
ct[1] = getct(cardt);
cout << "Enter the value of the first card(2-A):";
cin >>cardv;
cv[1] = getcv(cardv);
cout << "Enter the type of the second card (S,H,C,D):";
cin >>cardt;
ct[2] = getct(cardt);
cout << "Enter the value of the second card(2-A):";
cin >>cardv;
cv[2] = getcv(cardv);

cout<<'\n'<<ct[1]<<"/"<<cv[1]<<"/"<<ct[2]<<"/"<<cv[2]<<endl;
}


//this function goes through all the possible values for val and assign it the corresponding int
int getcv(char cval)
{
int cv;

if(cval=='A')
cv=14;
else if(cval=='a')
cv=14;
else if(cval=='K')
cv=13;
else if(cval=='k')
cv=13;
else if(cval=='Q')
cv=12;
else if(cval=='q')
cv=12;
else if(cval=='J')
cv=11;
else if(cval=='j')
cv=11;
else if(cval=='1')
cv=10; //because the if the user enters 10 as the value the char variable is gonna take only the 1...
else
cv=(static_cast(cval))-48; //if val is not A,K,Q,J its a number from 2 to 10!...in ascii 0 is 48 so remove 48 from the char value


return(cv);
}


//this function goes through the 4 possible type value and converts it to the int format
int getct(char ctyp)
{
int ct;

if(ctyp=='0') //if ctyp gets value 0 user is reasked for it
cin >> ctyp;


if(ctyp=='S')
ct=1;
else if(ctyp=='s')
ct=1;
else if(ctyp=='H')
ct=2;
else if(ctyp=='h')
ct=2;
else if(ctyp=='C')
ct=3;
else if(ctyp=='c')
ct=3;
else if(ctyp=='D')
ct=4;
else if(ctyp=='d')
ct=4;
else
ct=0; //if no value correspond return value 0 (invalid)


return(ct);
}

2 réponses

platon179 Messages postés 237 Date d'inscription lundi 20 mai 2002 Statut Membre Dernière intervention 22 juillet 2011 2
16 févr. 2006 à 18:42
Salut :)
Pourquoi est-ce que tu ne fais pas une lecture de string, dans ce cas, tu n'auras plus ces problèmes...
@+
0
bayeto Messages postés 224 Date d'inscription mardi 12 août 2003 Statut Membre Dernière intervention 18 octobre 2010
16 févr. 2006 à 21:28
Comme le dis Platon, les string sont ce qu'il ya de mieux. Ou Alors un cin.getline pour un char* ...
0
Rejoignez-nous