Thread: Looping Problem case 3

  1. #1
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112

    Exclamation Looping Problem case 3

    ok first of all, i hoping this readable,
    Code:
      
      int main() 
                {
                 int x;
                 int y;
                 int n;
                 int holdin;
                 int result=0;
                 printf("First Value =");
                   scanf("%d",&x);
                 printf("Divide Value =");
                   scanf("%d",&y);
                 printf("Looping Times =");
                   scanf("%d",&n);
    
              for(int m=1;m<n;m=m+1){
                   
                   holdin=x+(m-1)*y;
                   result=result+holdin;
                   printf("%d+",holdin);
                   
                                                 }
                   
                   holdin=x+(m-1)*y;
                   result=result+holdin;
                   printf("%d=%d",holdin,result);
               }
    wrong at this line after the curly brackets,
    Code:
    holdin=x+(m-1)*y;
    it says '-fpermissive' again like the older thread with loop problem that i began to with the loop problems,
    the reason i am adding the new line after curly brackets it because

    if the loop times was 5
    it only count up 4 times because
    Code:
    for(int m=1;m<n;m=m+1)
    int m=1 not 0 and the increment only 4 times with the final result m=5
    but when i adding the line, "-fpermissive" thing comes up,
    any ideas?

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by loserone+_+ View Post
    ok first of all, i hoping this readable,
    No, it's still a mess. You really have to work on your coding style.

    Quote Originally Posted by loserone+_+ View Post
    it says '-fpermissive' again like the older thread with loop problem that i began to with the loop problems,
    Copy'n'paste the full warning/error. Don't paraphrase it.
    And if the problem is connected to another thread, why do you open a new one?

    Code:
    for(int m=1;m<n;m=m+1)
    {
        holdin=x+(m-1)*y;
        result=result+holdin;
        printf("%d+",holdin);
    }
    holdin=x+(m-1)*y;
    You are declaring 'm' in the initialization part of the for-loop (a C99 feature), thus it's only visible within the body of the for-loop.
    Since 'm' is not declared outside of the for-loop, you get the error/warning from the compiler.

    Bye, Andreas

  3. #3
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112
    No, it's still a mess. You really have to work on your coding style.
    lol maybe i need a practice for the indentation

    Since 'm' is not declared outside of the for-loop, you get the error/warning from the compiler.
    simple way i cant using the 'm' variable after the for loop right.
    and that makes me thinking variable on "for loop" was only used once,

    And if the problem is connected to another thread, why do you open a new one?
    i dont think thats the same from my first thread until u say about i cant used the variable on "for loop" again,
    i believe that's the same problem.
    sorry for double post the problem,
    this case is closed

  4. #4
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by loserone+_+ View Post
    simple way i cant using the 'm' variable after the for loop right.
    You can use 'm' after the for loop if you declare it outside the for-loop.

    Bye, Andreas

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. looping problem?
    By nyekknyakk in forum C Programming
    Replies: 9
    Last Post: 08-20-2010, 11:02 AM
  2. Looping a Switch Case
    By dan g in forum C++ Programming
    Replies: 2
    Last Post: 01-13-2007, 06:36 PM
  3. Looping problem
    By vutek0328 in forum C Programming
    Replies: 8
    Last Post: 09-22-2006, 01:45 AM
  4. looping problem
    By trixxma in forum C Programming
    Replies: 10
    Last Post: 05-20-2006, 10:17 PM
  5. upper case to lower case problem
    By Jasonymk in forum C++ Programming
    Replies: 3
    Last Post: 04-27-2003, 05:35 AM