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
Post a Comment