COULIX un pc pour les attirer ... | Taz@PPC a écrit :
petites remarques en passant:
- rajoute un joli "using namespace std;" apres tes #include
- pourquoi utiliser un char[] pour lire cin? tu connais les string, alors utilises les. dans ton programme, l'emploi sera le meme et le rendra plus robuste
- personnellement je préféres l'appel explicite au constructeur (string t("n" )) à la synthaxe = (string t="n" )
- plus généralement, voici le constructeur d'initialisation des string string(char caractere, unsigned N) qui construit une chaine de N caractere. peut etre préférable dans la remarque précédente
- attention aux opérateurs = et ==. tu peux aussi utiliser les opérateurs -- (pre et post) de la meme maniere que ++ (--ace au lieu de ace=ace-1)
- attention: en C++, on indexe les éléments de 0 à N-1, donc ta boucle doit etre for(unsigned i=0; i<52; ++i), c'est à dire avec une infériorité stricte
|
j utilise char par ce que sa me permet d utiliser strlen (input)
et sa marche pas si input est string.
>> c bon j ai trouver input.c_str() mon programme marche presque c pas bien nickel encore mais bon.
Code :
- #include <iostream>
- #include <string>
- #include <cstring>
- int gcd(int a, int b){ //function who send back the commun diviser of two numbers
- int y,z; //to test if (card % total) can be simplified.
- while(a!=b){ // if nbr of card=0 to avoid division by zero
- if (a==0){
- a=1; return a;}
- if(a>b){
- z=a;
- y=b;}
- else if(a<b){
- z=b;
- y=a;}
- else{
- z=a;
- y=a;}
- b=y;
- a=z-y;}
- return a; }
- float percentage (float a, float b) { //function who calcute the probability percentage
- float u;
- if (a==0)
- {
- u = 0;
- return u; }
- else
- u = ((a / b)*100);
- return u; }
- void intro ()
- {
- cout <<" \n";
- cout << " ///\\ \n";
- cout << " (@ @) \n";
- cout << " +---oOO----(_)---Ooo-----+ \n";
- cout << " | TAGMC21 © I \n";
- cout << " I Sibt jan 2003 | \n";
- cout << " I V 0.1 | \n";
- cout << " +------------------------+ \n";
- cout << " |__|__| \n";
- cout << " || || \n";
- cout << " ooO Ooo \n";
- cout <<" \n";
- cout <<"ASSIGNEMENT 3 : § Card counting § \n";
- cout <<" \n"<<endl;;
- cout << "This program displays the probability of the remaining card in the deck \n";
- cout << "being the next card.\n";
- cout << "ENTER [0] to quit\n";
- cout << "\n"; }
- bool test (char a[], int b)
- {
- int j = 0;
- do {
- //for (int j=0; (j <= b) ;j++ )
- //{
- if (a [j] == 'A' )
- { return true; }
- else return false;
- }
- while (j<= 5);
- return false;
- }
- int main()
- {
- string t = "n";
- int total = 52;
- char input [total];
- int ace = 4;
- int king = 4;
- int queen = 4;
- int jack = 4;
- int ten = 4;
- int nine = 4;
- int eight = 4;
- int seven = 4;
- int six = 4;
- int five = 4;
- int four = 4;
- int three = 4;
- int two = 4;
- intro ();
- do {
- do {
- // check if the input enterered are not greater than the deck
- cout << "\n";
- cout << "Enter the cards you want to remove from the deck ( " << total << " cards) [AKQJT98765432] \n";
- cout << "\n";
- cin >> input;
- // if (test (input,total) == true)
- // { cout << "okkkkk\n";}
- // else { cout << " nooooo \n";}
- if (strlen (input)> total) { // strlen return the number of caracteres in input before \0
- cout << "error, you can not take more cards than there is left in the deck";
- cout << "\n"; }
- }
- while (strlen (input)> total);
- // if ((total <= (strlen (input))) && ((test(input) == true)) )
- //{ cout << "Finish, only one more card possible \n";
- // cout << "Do you want to quit ? \n";
- // cin >> t;
- // if (t!= "n" ) break;
- // else main ();
- //}
- for (int i=0; i<=total;i++) {
- if (input [i]=='A') {if (ace < 1) {cout << "Error you already took the 4 Aces\n"; break; } else (ace = ace--); }
- else if (input [i]=='K' ) {if (king==0) {cout << "Error you already took the 4 kings\n"; break; } else king = king-1; }
- else if (input [i]=='Q' ) {if (queen==0) {cout << "Error you already took the 4 Queens\n"; break; } else queen = queen-1; }
- else if (input [i]=='J' ) {if (jack==0) {cout << "Error you already took the 4 Jacks\n"; break; } else jack =jack-1; }
- else if (input [i]=='T' ) {if (ten==0) {cout << "Error you already took the 4 tens\n"; break; } else ten = ten-1; }
- else if (input [i]=='9' ) {if (nine==0) {cout << "Error you already took the 4 nines\n"; break; } else nine = nine-1; }
- else if (input [i]=='8' ) {if (eight==0) {cout << "Error you already took the 4 eights\n"; break; } else eight = eight-1; }
- else if (input [i]=='7' ) {if (seven==0) {cout << "Error you already took the 4 sevens\n"; break; } else seven =seven-1; }
- else if (input [i]=='6' ) {if (six==0) {cout << "Error you already took the 4 sixs\n"; break; } else six = six-1; }
- else if (input [i]=='5' ) {if (five==0) {cout << "Error you already took the 4 fives\n"; break; } else five = five-1; }
- else if (input [i]=='4' ) {if (four==0) {cout << "Error you already took the 4 fours\n"; break; } else four = four-1; }
- else if (input [i]=='3' ) {if (three==0) {cout << "Error you already took the 4 threes\n"; break; } else three = three-1; }
- else if (input [i]=='2' ) {if (two==0) {cout << "Error you already took the 4 twos\n"; break; } else two = two-1; }
- else break; }
- total = (ace + king + queen + jack + ten + nine + eight + seven + six + five + four + three + two);
- cout << " Ace : " << (ace/(gcd(ace,total))) << " in " << (total/(gcd(ace,total))) << "(" << (percentage (ace,total)) << "%)" << "\n";
- cout << " king : " << (king/(gcd(king,total))) << " in " << (total/(gcd(king,total))) << "(" << (percentage (king,total)) << "%)" << "\n";
- cout << " queen : " << (queen/(gcd(queen,total))) << " in " << (total/(gcd(queen,total))) << "(" << (percentage (queen,total)) << "%)" <<"\n";
- cout << " jack : " << (jack/(gcd(jack,total))) << " in " << (total/(gcd(jack,total))) << "(" << (percentage (jack,total)) << "%)" <<"\n";
- cout << " ten : " << (ten/(gcd(ten,total))) << " in " << (total/(gcd(ten,total))) << "(" << (percentage (ten,total)) << "%)" <<"\n";
- cout << " nine : " << (nine/(gcd(nine,total))) << " in " << (total/(gcd(nine,total))) << "(" << (percentage (nine,total)) << "%)" <<"\n";
- cout << " eight : " << (eight/(gcd(eight,total))) << " in " << (total/(gcd(eight,total))) << "(" << (percentage (eight,total)) << "%)" <<"\n";
- cout << " seven : " << (seven/(gcd(seven,total))) << " in " << (total/(gcd(seven,total))) << "(" << (percentage (seven,total)) << "%)" << "\n";
- cout << " six : " << (six/(gcd(six,total))) << " in " << (total/(gcd(six,total))) << "(" << (percentage (six,total)) << "%)" <<"\n";
- cout << " five : " << (five/(gcd(five,total))) << " in " << (total/(gcd(five,total))) << "(" << (percentage (five,total)) << "%)" << "\n";
- cout << " four : " << (four/(gcd(four,total))) << " in " << (total/(gcd(four,total))) << "(" << (percentage (four,total)) << "%)" <<"\n";
- cout << " three : " << (three/(gcd(three,total))) << " in " << (total/(gcd(three,total))) << "(" << (percentage (three,total)) << "%)" <<"\n";
- cout << " two : " << (two/(gcd(two,total))) << " in " << (total/(gcd(two,total))) << "(" << (percentage (two,total)) << "%)" <<"\n";
- }
- while (input[0]!= '0');
- }
|
sinon j essaye de fair eune fonction booleen quei renvoie true quand elle test si le input entrer ne contient que les caracteres voulut ('A','Q','K' ect..) j aimerai bien un peu d aide la dessus Message édité par COULIX le 03-01-2003 à 12:37:49 ---------------
.... et dans les tenebres les lier
|