help me please

This is a discussion on help me please within the C Programming forums, part of the General Programming Boards category; hello, I'm a beginner in c programming and i want you to help me to complete my little console game ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    4

    help me please

    hello,
    I'm a beginner in c programming and i want you to help me to complete my little console game which is a famous game " guess the number" here is my code :
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <conio.h>
    void  main()
     {
    
        int N,x,essai,T,i,;
    
    
        printf(" veillez choisir entre le mode machine (1) ou le mode joueur  tapez 1 pour le mode machine \n ");
    
        scanf("%d:\n",&T);
    
    
    
    
       randomize(); // initialisation de rand
    if(T==1)
    {
       N = rand()%100;
       printf(" joueur : devinez le nombre N compris entre 0 et 100\n ");
    }
    else
    {
    printf(" joueur 1 : veillez saisir un nombre compris entre 0 et 100\n");
    
    scanf("%d:\n",&N);
    
    printf(" joueur 2: devinez le nombre N compris entre 0 et 100\n ");
    
    clrscr();
    }
       essai=1;
    
    
    
    
    
       scanf("%d:\n",&x);
    
               while(x!=N && essai<=10)
    
                 {
                     if(x<N)
                     {
                         printf("x<N:\n");
                     }
                     else
                     {
                      printf("x>N:\n");
                     }
    
                         printf("Nouvel essai joueur\n");
    
                    scanf("%d:\n",&x);
    
                          essai++ ;
    
                 }
    
              if(essai<=10)
              {
                 printf("\n bravo, vous avez pu deviner le nombre en %d essais",essai);
              }
           else
           {
                 printf("dsl , vous avez échoué à l'épreuve, bonne chance la prochaine fois");
           }
    
    
    
    
       getch();
     }
    now i want to add a score sorting depending on the number of " essai ", with just using a tables .
    so if any one can help me i will be Grateful.
    Thank you in advance.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Welcome to the forum, khorkoch!

    I like French, but never studied it, so you're pretty much out of luck if you're too busy to translate it. I'm not going to work through Google's translator for you.

    Guess the Number is a binary search game, (if you're a bit clever), as we played it as kids. Score sorting? What's the problem? Put the scores into an array and sort them, yes?

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    4
    first of all , I'm really a beginner in c programming this why i asked for help so please don't tell me " as we played it as kids. Score sorting? What's the problem? Put the scores into an array and sort them, yes? " , concerning french it's does not matter , because it is just a comment but here is the code completely in English:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <conio.h>
    void  main()
     {
    
        int N,x,guessesT,i,top[10],D,j;
    
    
        printf(" please choose between machine mode (1) and player mode tape 1 for machine mode  \n ");
    
        scanf("%d:\n",&T);
    
    
    
    
       randomize(); // rand initialization
    if(T==1)
    {
       N = rand()%100;
       printf(" player : guess the number between 0 and 100 \n ");
    }
    else
    {
    printf(" player 1 : insert a number between 0 and 100 \n");
    
    scanf("%d:\n",&N);
    
    printf(" player 2: guess the number between 0 and 100\n ");
    
    clrscr();
    }
       essai=1;
    
    
    
    
    
       scanf("%d:\n",&x);
    
               while(x!=N && guesses<=10)
    
                 {
                     if(x<N)
                     {
                         printf("x<N:\n");
                     }
                     else
                     {
                      printf("x>N:\n");
                     }
    
                         printf("guess again \n");
    
                    scanf("%d:\n",&x);
    
                          essai++ ;
    
                 }
    
              if(essai<=10)
              {
                 printf("\n congratulation you succeeded in  %d guesses ",guesses);
              }
           else
           {
                 printf("sorry, game over ");
           }
    
    
    
    
       getch();
     }

  4. #4
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Glyfada,Athens
    Posts
    2,650
    Note essai is declared as guessesT.Translation missed some spots :P

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Don't be upset. This was a game we sometimes played as kids to decide things like which team would bat first in baseball, etc.

    Scores based on the number of guesses? Something like:

    Code:
    int scores[NumOfPlayers]={0};
    
    if(guesses < 5)
       score = 25;
    else if(guesses < 10)
       score = 20;
    else if(guesses < 15)
       score = 15;
    else if(guesses < 20)
       score = 10;
    else if(guesses < 30)
       score = 5;
    
    scores[PlayersNumber]=score;
    
    or
    
    scores[PlayersNumber]+=score; //keep a summation of scores for each player.
    Something like that? You could make an array and use score[i]

  6. #6
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    383
    Your main function should be declared as int main() or int main(void), and it should return 0 at the end to indicate successful execution.

    Where is the randomize function defined? It's not a standard C function.

  7. #7
    Registered User
    Join Date
    Nov 2012
    Posts
    4
    thank you adak but it did not work .I want to do a descending sorting of guesses using table ( "for" loop) without "score".
    thank you christop for your notice but it work normally and very well using borland c++.

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    OK, you have a top[] array for the games with the fewest number of guesses. Do you want to include the player's name? A struct might be too difficult atm, but a "parallel" char array of names[10][length of names] to match with int top[], would be OK.


    This is Insertion sort, and will sort either ascending or descending, depending on the comparison you have in the code:

    Code:
    //call to the function:
    insertionSort(top, 0, n);
    
    void insertionSort(int A[], int lo, int hi) {
      int i, j, val; 
      j=hi;   
      for(i=lo+1;i<hi;i++) {  
        val = A[i];
        j = i-1;
        while(A[j] < val) {
          A[j + 1] = A[j];
          --j;
          if(j<0) break;
        }   
        A[j+1] = val;
      }
    }
    If you decide to go with the players name also, this will need to be changed, but we can help you with that.

  9. #9
    Registered User
    Join Date
    Nov 2012
    Posts
    4
    thank you very much adak for your helping and your effort .but I didn't understand your code , so if you can integrate it to mine so that it will be coherent .no problem if we go with the players name also.

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I'll be back in a few hours. Try to add the function I posted, into your program. Outside of main().

    Post this prototype, below the include files in the program, and above the first function (which should be main()):
    Code:
    void insertionSort(int A[], int lo, int hi);  //function prototype for insertionSort()
    Then in your program, when the player has finished, and you have their number of guesses, we'll check their number to see if it's a one of the top 10, and if it is, we'll write it into the top scores data file.

    Back in a few hours, see what you can do with it.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21