i am trying to put the length width part into it's own function, so that i dont have a code repeat...i cant seem to be able to do this....could you make some suggestions or, even better, edit the code? thanks

Code:
#include <iostream>	
using namespace std;
void mainA();
void mainB();
void end();
int main()
{
    cout<<"Enter 1 for the object to have area,\nEnter 2 for the object not to have area: ";
    int A;
    cin>> A;
    cout<<"\n";
    if (A != 1 & A != 2){
        main();
    }
    else{
        if (A != 2){
            mainA();
        }
        else if (A != 1){
            mainB();
        }
    }
}
void mainA(){
    cout<<"Input The Length: ";
    int A;
    cin>> A;
    cout<<"Input The Width: ";
    int B;
    cin>> B;
    cout<<"\n\n";
    for (int a = 0; a < A; a++){
        for (int b = 0; b < B; b++){
            cout<<"O";
        }
        cout<<"\n";
    }        
    end();
}
void mainB()
{
    cout<<"Input The Length: ";
    int A;
    cin>> A;
    cout<<"Input The Width: ";
    int B;
    cin>> B;
    cout<<"\n\n";
    for (int a = 0; a < B; a++){
        cout<<"O";
    }
    if (A > 1){
        cout<<"\n";
        if (B > 1){
            for (int a = 0; a < (A - 2); a++){
                cout<<"O";
                for (int b = 0; b < (B - 2); b++){
                    cout<<" ";
                }
                cout<<"O\n";
            }
            for (int c = 0; c < B; c++){
                cout<<"O";
            }
        }
        else{
            for (int a = 0; a < (A - 1); a++){
                cout<<"O\n";
            }
        }
    }
    else{
        cout<<"\n";
    }
    end();
}
void end()
{
    cout<<"\n\n\n";
    cout<<"This Program was created by: Joshua\n";
    cout<<"On 1-29-05\n\n";
    int Z;
    cin>> Z;
}