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

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2009
Posts: 5
Reputation: Wtyy is an unknown quantity at this point 
Solved Threads: 0
Wtyy Wtyy is offline Offline
Newbie Poster

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

 
0
  #1
Oct 31st, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 201
Reputation: yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold 
Solved Threads: 35
yellowSnow's Avatar
yellowSnow yellowSnow is offline Offline
Posting Whiz in Training
 
0
  #2
Oct 31st, 2009
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.
Manic twiddler of bits
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 5
Reputation: Wtyy is an unknown quantity at this point 
Solved Threads: 0
Wtyy Wtyy is offline Offline
Newbie Poster
 
-1
  #3
Oct 31st, 2009
Originally Posted by yellowSnow View Post
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;
}
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,443
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 250
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c
 
0
  #4
Oct 31st, 2009
  1. ++*count;
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

Message:



Other Threads in the C Forum
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC