I am writing a guessing game, player could only enter number ten times, after that, a "End" message should print.

the random name =ran1
your enter number = a
count the enter times = b

I wrote :

if ( ran1 != a)
{
b++;
}

printf("the count number: %d", b);
printf("\nthat's the end.");

but it doesn't work, the count number is still zero!!!!


however, I wrote :

if ( ran1 == a)
{
b++;
}
printf("the count number: %d", b);
printf("\nthat's the end.");

it works, the count number is can change!!!!!


what's the problem?

Post your code - or at least the minimal amount that compiles and illustrates your issue.
Also, "if" is not a function.

[QUOTE=yellowSnow;1032330]Post your code - or at least the minimal amount that compiles and illustrates your issue.
Also, "if" is not a function.[/QUOTE]

ok, this is the codes,
although I satisfy the condition, count hasn't change, still zero
I don't know why..........

#include "stdafx.h"
#include "stdlib.h"
#include "time.h"
void calCount (int* ranNum, int* num1, int* count);


int _tmain(int argc, _TCHAR* argv[])
{
    int ranNum;
    int num1;
    int count = 0;

    srand(time(NULL));
    ranNum = (rand()%20) + 1;

    printf("%d\n", ranNum);

    printf("\nGuess:    ");
    scanf("%d", &num1);


        calCount (&ranNum, &num1, &count);

       printf("count amount: %d", count);


    return 0;
}

void calCount (int* ranNum, int* num1, int* count)
{
        if (*ranNum != *num1)
        *count++;

               if (*count == 1)
           printf("\nOK\n");

        return;
}
++*count;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.