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?

Edited 7 Years Ago by Wtyy: n/a

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

Edited 7 Years Ago by yellowSnow: n/a

[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;
}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.