ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i compile in gcc
-----------------------------
gcc -ansi 87b.c -o test
----------------------------
but i could not understand this prog the use of
-------------
right = 0;
------------
right = 1;
-------------
if(!right)
------------
for(chances=0; chances<3 && !right; chances++) "only the not right use why"
Code:
#include <stdio.h>
int main(void)
{
int answer, count , chances, right;
for (count=1; count<11; count++){
printf("What is %d + %d?", count, count);
scanf("%d" , &answer);
if (answer == count+count) printf("Right!\n");
else{
printf("Sorry, you're wrong\n");
printf("Try again\n");
right = 0;
/* nested for */
for(chances=0; chances<3 && !right; chances++){
printf("What is %d + %d?", count, count);
scanf("%d" , &answer);
if (answer == count+count){
printf("Right!\n");
right = 1;
}
}
/*if answer still wrong, tell user */
if(!right)
printf("What is %d + %d?", count, count);
}
}
return 0;
}
hi
no. no u got this wrong
for ex.
we have x=1;
then if we have this statement
if(x==1)
will check whether x is equal to 1
so if(1) means that the if statement is true always and it will execute the block of the if statenment
1 = true
and 0 = false
in boolean
so if u use if(1) in a c program then the block below it will b executed all the time
so in ur program if right is set to 0 then
then the block of
if(!right) will be executed
i.e "printf("What is %d + %d?", count, count);"
also if(!right ) is same as (if right==0)
when u use some kinds of flags we geneally use this
i hope now u get it
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.