1. ## Need Help

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;
}```

2. i was also wondering if you could help me with replacing the O with some kind of line. If you compile the code and run the program, you see that the boxes look like this

OOOOOOO
OOOOOOO
OOOOOOO

i only know how to use cout<< to display text.....
i would like to learn how to do the actual visual side of C++, and i would appreciate it, if anyone could give me a tutorial website that i could learn how to do it.

3. of course the "boxes" will look like O's when you have this in your code
Code:
`cout<<"O";`
this site has many tutorials

4. but i have looked, and maybe i missed it, but when i put this (look bleow) into a funtion, and then call the function in mainA or mainB it says that there was no such int, and when i create that, it is not the same value as in the new function(below)

void mainAA(){
cout<<"Input The Length: ";
int A;
cin>> A;
cout<<"Input The Width: ";
int B;
cin>> B;
cout<<"\n\n";
}

5. Code:
```void mainAA(){

int A, B;

cout<<"Input The Length: ";
cin>> A;
cout<<"Input The Width: ";
cin>> B;
cout<<"\n\n";

}```

6. You could declare int A and B globally rather then within the void mainAA function and that should fix your problem

7. Here is a good link on console programming . You will definetly gain some knowledge going through the tutorials.

There are more than just console tuts here so scroll down slighlty and you will see the 6 part console tutorial.

8. Why on earth did you call your functions "mainA" and "mainB"? They've got to be some of the most unintuitive function names I've ever seen.

Also, did you mean to have:
Code:
`if (A != 1 & A != 2){`

Quzah.

9. Here's what i did:

Code:
```#include <iostream>
using namespace std;
void mainA();
void mainB();
void end();
int main()
{
int A, B, C;
cout<<"Enter 1 for the object to have area OR Enter 2 for the object not to have area: ";
cin>> A;
cout<<"Input The Length: ";
cin>> B;
cout<<"Input The Width: ";
cin>> C;
cout<<"\n\n";
if (A != 1 & A != 2){
main();
}
else{
if (A != 2){
mainA();
}
else if (A != 1){
mainB();
}
}
}
void mainA(){
int B, C;
for (int a = 0; a < B; a++){
for (int b = 0; b < C; b++){
cout<<"O";
}
cout<<"\n";
}
end();
}
void mainB()
{
int B, C;
for (int a = 0; a < C; a++){
cout<<"O";
}
if (B > 1){
cout<<"\n";
if (C > 1){
for (int a = 0; a < (B - 2); a++){
cout<<"O";
for (int b = 0; b < (C - 2); b++){
cout<<" ";
}
cout<<"O\n";
}
for (int c = 0; c < C; c++){
cout<<"O";
}
}
else{
for (int a = 0; a < (B - 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;
}```
The compiler allowed it to be compiled, but when i ran the program when you enter all the values, it will keep displaying O
It continues to scroll, and doesnt stop.

Q: What Did I do Wrong?
because i cant see what is wrong about it.

10. TO quzah:

yes, i did, that repeats the program if you do not enter 1 or 2

11. You variables in main(), aka A, B, C are unique to main(). You will not be able to use them outside of this function. To access them you would need to make the variables global or pass them to the function.
Code:
```#include <iostream>

using namespace std;

int A; //global

void myFunc(int); //function takes an integer value

int main(void){

int B; //local

cout<< "Enter A: ";
cin >> A;
cin.get();
cout << "Enter B: ";
cin >> B;

myFunc(B);

cin.get();
return 0;
}
void myFunc(int C) { //can use whatever variable name you want

cout << A;
cout << C;
}```

12. I'd recommend adding 2 functions. getLength() and getWidth() each of which returns an integer. That way you don't need to use any globals.
Code:
```int getLength()
{
int A;

cout << "Input The Length: ";
cin >> A;
cout << endl;

return A;
}```
Then in the calling functions you can use int A = getLength();. And do the same for getWidth().

 Now that I think about it, 2 functions would be redundant since you can use 1 and name it something like getSide.

Example...
Code:
```void mainA()
{
int A = getLength();
int B = getWidth();

for (int a = 0; a < A; a++){
for (int b = 0; b < B; b++){
cout<<"O";
}
cout<<"\n";
}
}```
Additionally, clean up your int main(). I shudder whenever I see a recursion to main(). Here's an example that I cleaned up for you...
Code:
```int main()
{
int A = 0;

do {

cout<<"Enter 1 for the object to have area,\nEnter 2 for the object not to have area: ";
cin>> A;
cout<<"\n";

if (A == 1)
mainA();
else if (A == 2)
mainB();

} while ( A != 1 && A != 2 );

end(); // remove this function call from mainA and mainB

return 0;
}```

`if( foo != bar && foo != baz )`