944,183 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 327
  • C RSS
Oct 31st, 2009
0

HELP! The "if" function doesn't work!!!

Expand Post »
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?
Last edited by Wtyy; Oct 31st, 2009 at 3:07 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Wtyy is offline Offline
5 posts
since Oct 2009
Oct 31st, 2009
0
Re: HELP! The "if" function doesn't work!!!
Post your code - or at least the minimal amount that compiles and illustrates your issue.
Also, "if" is not a function.
Last edited by yellowSnow; Oct 31st, 2009 at 7:56 am.
Reputation Points: 651
Solved Threads: 35
Posting Whiz in Training
yellowSnow is offline Offline
201 posts
since Jul 2009
Oct 31st, 2009
-1
Re: HELP! The "if" function doesn't work!!!
Click to Expand / Collapse  Quote originally posted by yellowSnow ...
Post your code - or at least the minimal amount that compiles and illustrates your issue.
Also, "if" is not a function.
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;
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Wtyy is offline Offline
5 posts
since Oct 2009
Oct 31st, 2009
0
Re: HELP! The "if" function doesn't work!!!
  1. ++*count;
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Need help
Next Thread in C Forum Timeline: How to get the "Program Counter"





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC