main() use in other functions that main() uses.

In findNum(), I use a loop to test for characters(Each alphabetical character is represented by a number), and if they aren't characters, I try to use main() again.

The problem: to use function findNum() I have to declare it before main(), and to use main(), I have to declare it before findNum(). Got any tips on how to use main() in a function which is used by main()?

Heres a clip of my code:

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
// cAt = character At. aNum = the number which each alphabetical 
//character represents: A-Z 65-90, a-z 90-122, _=32, " "=95

int findNum(){ int i=0; int cAt, lengthOf, aNum;
while(i<myName.length()){
        cAt=myName.at(i);
        aNum=myName.at(i);
        lengthOf=myName.length();
        loop:
             if(cAt>=65 || cAt<=90){
                  i++;
                  goto loop;} 
             else if(cAt>=97 || cAt<=122){
                  i++;
                  goto loop;}
             else if(cAt>90 && cAt<97){
                  if(!cAt==95)cout<<"Please enter a valid name"<<main();
             }
             else if(cAt<65 && !cAt==32)cout<<"Please enter a valid name"<<main();
             else if(cAt>122)cout<<"Please enter a valid name"<<main();
             else if(cAt==lengthOf){break;}       
}}

int main(){
    
    yourName();
    cin.ignore(); //When the enter button gets pressed, this keeps the program 
    findNum();                                         // from shutting down.
    cin.get(); //This keeps the program open after start-up.
    return 0;
}


Last edited on
You can use forward declarations:
1
2
3
4
5
6
7
8
9
10
11
int findNum();

int main()
{
   //...
}

int findNum()
{
   //...
}
But isn't a loop better than this approach?
ahh, thank you! What a simple answer. Haha
Topic archived. No new replies allowed.