aa and bb ot declalred???

Hello!
Please why do I get the error that aa and bb are not declared?
Aren't they?

Many thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
   for (int y=0;y<5;y++){
    int a8=rand()%10;
    int b8=rand()%20;
    int c8=rand()%10;
    int d8=rand()%20;
    int e8;
    int aa=(a8*d8)-(b8*c8);
    int bb=b8*d8;
    
    cout<<a8<<endl<<b8<<endl<<c8<<endl<<d8<<endl<<aa<<endl<<bb<<endl<<endl;
    cout << "fu2 result is: "<<fu2(a8, b8, c8, d8)<<endl<<endl;
                      }
                     
                                  int &fu2 = (aa < bb) ? aa : bb;

    for (int fu2i=2; fu2i<=fu2; fu2i++)
        while ((aa%fu2i==0) && (bb%fu2i==0))
        {
            aa /= fu2i;
          
            bb /= fu2i;
          
           cout<<"Funal fu2: "<<aa<<" / "<<bb<<endl<<endl;
        }


p.s. just to tell that other variables, a8to d8, are fine generating, and fu2 is bravely counting the result!!!
Last edited on
Scope. You have essentially:
1
2
3
4
{
  int aa = 7;
}
int fu = aa; // error 

Variables declared within block scope (lines 2-4) cease to exist at the end of the block.

This would be ok:
1
2
3
4
5
int aa = 0;
{
  aa = 7;
}
int fu = aa;

Topic archived. No new replies allowed.