fpermissive flag?

I've been working on a code for an Armstrong problem, but when trying to compile the code, I got this error:

prog4a.cpp: In function ‘int main()’:
prog4a.cpp:42:25: error: name lookup of ‘i’ changed for ISO ‘for’ scoping [-fpermissive]
answer = getRaiseAndAdd(i);
^
prog4a.cpp:42:25: note: (if you use ‘-fpermissive’ G++ will accept your code)


I tried Googling the -fpermissive flag, but could not find any help on how to prevent it from showing as an error. Any suggestions?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>

using namespace std;

//Function name: getRaiseAndAdd
//Purpose: Calculate each digit cubed and the sum of the results.
//We are sending in the current number from the loop starting at 100 and
//counting one by one to 999.
//Parameters: &numberInput
//Return value: Result of adding 3 numbers
int getRaiseAndAdd(int &numberInput)
{
int firstNumber, secondNumber, thirdNumber;
int remainder;
int sum;
int firstPower, secondPower, thirdPower;

firstNumber = numberInput / 100;
remainder = numberInput % 100;
secondNumber = remainder / 10;
thirdNumber = remainder % 10;

firstPower = firstNumber * firstNumber * firstNumber;
secondPower = secondNumber *secondNumber * secondNumber;
thirdPower = thirdNumber * thirdNumber * thirdNumber;

return sum = firstPower + secondPower + thirdPower;
}

int main()
{
int answer;
int originalNumber;

for(int i = 100; i < 1000; i++)
originalNumber = i;

answer = getRaiseAndAdd(i);
        {
        //Function name: is_Armstrong
        //Purpose: finding the Armstrong numbers
        //Parameters: answer
        //Return value: 0
        bool is_Armstrong (int answer);
        if(answer == originalNumber);
                {
                cout << "found an Armstrong number " << originalNumber << endl;
                }
        }

return 0;
}
Last edited on
You need to use curly braces in your for loop here
1
2
3
4
for(int i = 100; i < 1000; i++){
originalNumber = i;
answer = getRaiseAndAdd(i);
}

So that the variable i can be used in this part of your code answer = getRaiseAndAdd(i); That is the reason your getting this error
prog4a.cpp:42:25: error: name lookup of ‘i’ changed for ISO ‘for’ scoping [-fpermissive]
answer = getRaiseAndAdd(i);
Last edited on
Hi,

You can't have a function declaration there on line 44. remove the type if you meant it to be a function call.

Remove the semicolon from line 45.
In early C++ variable lifetime was different:
1
2
3
4
5
6
7
{
  int Y;
  for ( int X = 0; X < 42; ++X ) {
    // code
  }
// X and Y still exist
} // X and Y go out of scope 

That did change in the (ISO) C++ standard:
1
2
3
4
5
6
7
8
{
  int Y;
  for ( int X = 0; X < 42; ++X ) {
    // code
  }
// X is out of scope; does not exist any more
// Y still exists
} //  Y goes out of scope 

The compiler has a command line option that makes the compiler forget the standard and operate in the early mode. This allows recompilation of legacy code. If it did not have legacy support and be "helpful", then the error would be undeclared identifier 'i'.


man gcc and look for "fpermissive" within.
(Does Google treat prefix hyphen as logical NOT?)
Topic archived. No new replies allowed.