Thread: Help solving this loop question

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    90

    Help solving this loop question

    Hi all, i was having trouble solving this loop question,

    Write a program that compute the series S
    S=1-4+7-10+....+n (where n>10).

    here is my work so far:

    Code:
    #include <stdio.h>
    #include <conio.h>
    main()
     {
    int i,N,S;
    printf("Please enter No. of terms");
    scanf("%d",&N);
        if (N>10)
     {
    float sign=1;
      for(i=0;i<N;i++)
    S+=N*sign;
    sign=sign*-1;
     }
    printf(" the sum is : %d",S);
    getch();
    }
    the program doesn't do what its supposed to do and it gives me a warning " sign is assigned a value that is never used" , i dont know what to do please help.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Curly braces aren't in the language just to look pretty. (That is: which statements are in your for loop? Which statements should be in your for loop?)

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    90
    thanks for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. newb loop question
    By filio623 in forum C++ Programming
    Replies: 10
    Last Post: 09-18-2009, 02:54 PM
  2. For loop question
    By JuzMe in forum C++ Programming
    Replies: 11
    Last Post: 04-20-2009, 08:39 AM
  3. Loop question
    By kwood965 in forum C Programming
    Replies: 6
    Last Post: 10-29-2008, 11:12 PM
  4. simple for loop function question
    By felicityxiv in forum C Programming
    Replies: 7
    Last Post: 05-06-2006, 11:43 PM
  5. Please don't laugh...SIMPLE loop question!
    By the_lumin8or in forum C++ Programming
    Replies: 5
    Last Post: 03-31-2006, 01:08 PM