user input

This is a discussion on user input within the C Programming forums, part of the General Programming Boards category; sup.. umm i have created this prog.. that it ask the user at what number thats he/she wants the count ...

  1. #1
    unregisterd
    Guest

    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;
        }

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    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;
        }
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    unregisterd
    Guest
    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 =(

  4. #4
    unregisterd
    Guest
    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

  5. #5
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    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
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  6. #6
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953

    Re: user input

    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;
    }
    none...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  2. SSH Hacker Activity!! AAHHH!!
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 03-06-2005, 02:53 PM
  3. Nested Structures - User Input
    By shazg2000 in forum C Programming
    Replies: 2
    Last Post: 01-09-2005, 09:53 AM
  4. Getting user input for filename loop
    By jpchand in forum C++ Programming
    Replies: 1
    Last Post: 09-16-2003, 06:37 AM
  5. comparing user input
    By lambs4 in forum C Programming
    Replies: 5
    Last Post: 12-15-2002, 09:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21