c - Exit 1 if the total numbers input is not 8 -
i want user enter 8 numbers. if enter less 8 numbers, program exit.
what if statement should use?
should put in loop sum += if sum not 8 exit?
this got far doesn't work out:
int main() { int i, numb; int sum = 0; // loop enter 8 numb printf("enter 8 numbers"); if (i=0;i<8;i++) { scanf("%d", &numb); sum =+i; if (sum < 8) exit(1); } return (0); }
you want user enter 8 numbers , since have not mentioned sum, i'll assume doesn't matter is. remove inner if condition altogether , replace outer if loop.
here code:
for (i = 0; < 8; i++) { scanf("%d", &numb); //do whatever want number here
Comments
Post a Comment