mercredi 4 novembre 2020

my code compiles and execute perfectly but there is a part of that is like not read during execution

I'm some kind of beginner in programming, I know some Javascript, C# and now learning C. I created a simple mini-game in C called more or less(the computer chooses a random number, and you have to guess that number with minimum shots possible) so the code compiles and works perfectly except to show the congratulation part and the for loop to print the score. it is like they're not read at all. I tried to put the for loop inside the while loop. but it just scrapped the code. I also removed the int argc, char *argv[] but it did nothing. I tried to find help but nothing

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main (int argc, char *argv[])
{
    const int MAX = 100, MIN = 1;   
    int enteredNumber;
    int nombreMystere;
    int NombreDeCoups;
    //ask user for input (integer)
    printf("quel est le nombre? \n");
    scanf("%d", &enteredNumber);
    
    //generation of random number
    srand(time(NULL));//srand() must be used just once in any program
    nombreMystere = (rand() % (MAX - MIN + 1)) + MIN;//rand() is a function to provide random number

//program loop. repeats until user finds number
while (enteredNumber != nombreMystere)
    {
        if (enteredNumber < nombreMystere)//if loop, that shows if it,s more or less to provide
        {
            printf("c'est plus! \n");
        }
        else if (enteredNumber > nombreMystere)
        {
            printf("c'est moins! \n");
        }
        else 
        {
            printf("Bravo! Vous avez trouve le bon nombre");
        }
        
        printf("quel est le nombre? \n"); //reprompts user until find the number
        scanf("%d", &enteredNumber);
        
    }
    for (NombreDeCoups = 0; enteredNumber =! nombreMystere; NombreDeCoups++) // loop to give score of how many tries user did
        {
            printf("en %d coups", &NombreDeCoups);
        }
    
}```

Aucun commentaire:

Enregistrer un commentaire