c - I am able to count down to zero but i also want to be able to enter a negative number and have it count up to zero -


i trying write program allows user input number between negative 5 , positive 5 have number selected count zero.

#include <stdio.h> #include <unistd.h>  int main() {     int start;      //asking user input 1-5     {         printf("need number start countdown (1 - 5): "); //receiving user input         scanf("%d",&start);     } //while number less number 6     while(!(start<6));      //begin countdown     {         printf("%d\n",start);         start--;     }     while(start>0); //displaying number 0 when done     printf("0\n");     return(0); } 

this should on codereview site, start have problem in initial input loop

while(!(start<6)); 

will allow user enter value -1,234,567, needs be

while(start < -5 || start > 5); 

that said, in simplest form need if statement

if (start > 0) {     // code count down } else if (start < 0) {     // code count } else {     print("all done"); // user entered 0 } 

Comments

Popular posts from this blog

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -