| | |
HELP! The "if" function doesn't work!!!
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2009
Posts: 5
Reputation:
Solved Threads: 0
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?
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.
•
•
Join Date: Oct 2009
Posts: 5
Reputation:
Solved Threads: 0
-1
#3 Oct 31st, 2009
•
•
•
•
Post your code - or at least the minimal amount that compiles and illustrates your issue.
Also, "if" is not a function.
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;
}
0
#4 Oct 31st, 2009
C Syntax (Toggle Plain Text)
++*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
![]() |
Other Threads in the C Forum
- Previous Thread: Need help
- Next Thread: How to get the "Program Counter"
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays bash binarysearch changingto char character cm copyanyfile creafecopyofanytypeoffileinc createprocess() database directory dynamic execv feet fgets file floatingpointvalidation fork forloop framework function getlogicaldrivestrin givemetehcodez global grade graphics gtkwinlinux histogram homework ide include initialization input interest intmain() iso kernel keyboard kilometer lazy license linked linkedlist linux list lists looping loopinsideloop. lowest matrix meter microsoft mqqueue oddnumber odf openwebfoundation overwrite pause pdf pointer posix power process program programming pyramidusingturboccodes radix read recursion recv recvblocked research reversing segmentationfault sequential single socket socketprogramming spoonfeeding standard strchr string student suggestions system test testing threads turboc unix urboc user whythiscodecausesegmentationfault win32api windowsapi






