-
user input
sup.. umm i have created this prog.. that it ask the user at what number thats he/she wants the count down to start.. but.. i have tried but cant get it.. can someone please help me .. but.. using the same code as i have here.. using the for loop and the scanf.. im just following what the good sais to do .. hehe (teach your self c) .. thanx
Code:
#include <stdio.h>
#include <conio.h>
int main()
{
int i=0;
printf("Enter number to start count down from\n");
scanf("%d",&i);
for (i=0; i<20; i++)
printf("Count down staring at %d\n",i);
getch();
return 0;
}
-
Code:
#include <stdio.h>
#include <conio.h>
int main()
{
int i=0;
printf("Enter number to start count down from\n");
scanf("%d",&i);
while(i) // same as while(i != 0)
{
printf("Count down staring at %d\n",i);
--i;
}
getch();
return 0;
}
-
how can i do the same with out... going to the while loop.. hehe if i use the while loop then i would be sheating my self. cause i have not gotten to that part yet =(
-
can you please tell me what you just did here.. i just know part of it.. but then again part of it i dont understatd
for( ; i != 0; --i ) i understand the second part.. if not = to 0 then decrement i but i dont understand the first part
-
A for loop doesn't require anything beyond (;;). By setting i=0 you are in effect taking away the user's ability to start we he or she sees fit. If you want to use the for loop like you are trying, then try another variable for the user.
Code:
int length, count;
printf("Enter the number to count down from ");
scanf("%d", &length);
for(count = length; count >= 0; count--)
printf("%d ", count);
//...other code for output formatting
HTH
-
Re: user input
Quote:
Originally posted by unregisterd
Code:
#include <stdio.h>
#include <conio.h>
int main()
{
int i=0;
printf("Enter number to start count down from\n");
scanf("%d",&i);
for (i=0; i<20; i++)
printf("Count down staring at %d\n",i);
getch();
return 0;
}
You can try the following code:
Code:
#include <stdio.h>
#include <conio.h>
int main()
{
int i=0;
printf("Enter number to start count down from\n");
scanf("%d",&i);
printf("Count down staring at %d\n",i);
for (; i>0; i--)
printf("%d\n",i);
getch();
return 0;
}