Like Tree3Likes
  • 1 Post By anduril462
  • 2 Post By Tclausex

For And While Loop first problem had.

This is a discussion on For And While Loop first problem had. within the C Programming forums, part of the General Programming Boards category; look my code below Code: int x;int y; int main() { for(int n=1;n<3;n=n+1) { for(int m=1;m<3;m=m+1) { x=n+m;y=n-m; } } ...

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

    Question For And While Loop first problem had.

    look my code below
    Code:
    int x;int y;
    int main()
      {
      for(int n=1;n<3;n=n+1) {
      for(int m=1;m<3;m=m+1) {
      x=n+m;y=n-m;
      }
      }
      while(x>0) { 
      while(y<4) { 
      n=n+x+y;y=y-x-y;
      y=y+1;
      }
      x--;
      }
      if(!(n!=6)&&!(n!=-4)){
      printf("My Logic Was Right :) \n");
      }
      else {
      printf("Computer Login Wins :) \n");
      }
      }
    the expected output is for True condition of if
    and my logic of final result of me was
    Code:
    /*n=n+x+y (2+1+3) =6; m=m-x-y (2-3-3) =-4 */
    and when i compile the program using MingW32
    Code:
    n=n+x+y;y=y-x-y;
    on that line its givin error message
    error: name lookup of 'n' changed for ISO 'for' scoping [-fpermissive]
    note: if you use ('-fpermissive' G++ will accpt your code)
    okay thats my problem
    any ideas with that?

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,566
    Come on. 3 months here, and 62 posts, and you're still posting stuff with horrible indentation. Give us the courtesy of code that's easy to read, and we'll give you the courtesy of a speedy, helpful reply.

    Hint: your problem is one of scoping. More help, if needed, when you post readable code.
    AndiPersti likes this.

  3. #3
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112
    hm
    i cant make the simple readin' of my problem
    u say my code is unreadable?

  4. #4
    Registered User
    Join Date
    Nov 2011
    Location
    Saratoga, California, USA
    Posts
    334
    “Programs must be written for people to read, and only incidentally for machines to execute.”


  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,566
    Quote Originally Posted by loserone+_+ View Post
    hm
    i cant make the simple readin' of my problem
    u say my code is unreadable?
    You need to post code that is properly indented. I can read it, but it's awkward, and thus I wont read it. It is effectively unreadable.

  6. #6
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112
    yeahh i understand what u mean
    thanks much!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Do...While Loop problem
    By Paul Adams in forum C Programming
    Replies: 2
    Last Post: 03-27-2012, 12:49 PM
  2. do while loop got problem
    By yangss in forum C Programming
    Replies: 4
    Last Post: 09-03-2010, 03:33 AM
  3. do...while loop problem
    By geoffrey in forum C++ Programming
    Replies: 7
    Last Post: 03-09-2010, 02:49 PM
  4. while loop problem
    By chrismax2 in forum C++ Programming
    Replies: 2
    Last Post: 03-14-2005, 11:21 AM
  5. for loop problem
    By davidmccabe in forum C Programming
    Replies: 14
    Last Post: 11-20-2003, 01:22 PM

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