Thread: Initialize for loop using input from keyboard?

  1. #1
    Registered User
    Join Date
    Feb 2015
    Posts
    3

    Initialize for loop using input from keyboard?

    I'm not finished with this code, but I am stuck on this one glitch. This is what I have so far, and it's not working. Please let me know if you have any ideas on how to make this work.

    Code:
    int main()
    {
        /*Please input an n value greater than zero. Otherwise, exit the program by entering a carriage return*/
        printf("Please input an n value greater than zero. Otherwise, exit the program by entering a carriage return\n\n");
        int summation = 0, x, y;
        scanf("%d", y);
        
        
            for (y == x; summation <= M_E && x <= 34; x++)
            {
                summation = 1 / x;
                summation += summation;
            }
    
    
            printf("%12f\n\n", summation);
            system("pause");
            printf("Enter in a new n value to compute\n\n")
    
    
    }
    Thanks in advance

  2. #2
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by elsaj82 View Post
    Code:
    int main()
    {
        /*Please input an n value greater than zero. Otherwise, exit the program by entering a carriage return*/
        printf("Please input an n value greater than zero. Otherwise, exit the program by entering a carriage return\n\n");
        int summation = 0, x, y;
        scanf("%d", y);
        
        
            for (y == x; summation <= M_E && x <= 34; x++)
            {
                summation = 1 / x;
                summation += summation;
            }
    
    
            printf("%12f\n\n", summation);
            system("pause");
            printf("Enter in a new n value to compute\n\n")
    
    
    }
    Thanks in advance
    Take a look at how you are initializing your for loop. Plus main should return a value.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Initialize a variable in order to run loop at least once
    By samwillc in forum C++ Programming
    Replies: 9
    Last Post: 04-05-2013, 11:42 AM
  2. using a for loop to initialize an array
    By MSF1981 in forum C Programming
    Replies: 8
    Last Post: 02-22-2009, 11:34 PM
  3. Input of keyboard
    By Gordon in forum Windows Programming
    Replies: 3
    Last Post: 07-13-2008, 06:12 PM
  4. Need help with keyboard input
    By wiramu in forum C++ Programming
    Replies: 2
    Last Post: 11-28-2003, 02:44 PM
  5. Keyboard input ?
    By Malikive in forum Game Programming
    Replies: 4
    Last Post: 11-06-2001, 11:14 PM

Tags for this Thread