| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
This is for an assignment.. I've been working on it for a while tonight!!
I made a program that creates rectangles using ** based on user imput for width and height. ---I need to make it centered on an area that is assumed to be 80 characters wide------ PLEASE HELP ASAP !!!! Code:
void displayStars (int, int);
int main ()
{
int row, column;
char again;
do
{
cout << "Enter the number of rows and columns: ";
cin >> row >> column;
while (column < 2 || column > 60 && row < 2 || row > 60)
{
cout << "Invalid values for rows and columns" <<endl;
cout << "Please enter values between 2 - 60: " ;
cin >> row >> column;
}
cout << endl << endl;
displayStars(row, column); cout << endl << endl;
cout << " Do you want to create another rectangle? (Y/N) ";
cin >> again;
} while (again == 'Y' || again == 'y');
return 0;
}
void displayStars(int width, int height)
{
for (int across = 0; across < height; across++)
{
for (int down = 0; down < width; down++)
{
if ((down == 0) || (down == width - 1))
{
cout << "*";
}
else if ((across == 0) || (across == height - 1))
{
cout << "*";
}
else
{
cout << " ";
}
}
cout << endl;
}
}
|
|
#2
|
||||
|
||||
|
Use a loop with the following logic structure:
- Print each row out character by character - Print an astrik if you're on the first or last colums, or first or last rows - Otherwise, print a space Rewrite your displaysStars() function somewhat as follows (warning: untested code): Code:
void displayStars(int width, int height)
{
for (int down = 0; down < height; down++)
{
for (int across = 0; across < width; across++)
{
if ((down == 0) || (down == width - 1) || (across == 0) || (across == height - 1))
{
cout << "*";
}
else
{
cout << " ";
}
}
cout << endl;
}
}
__________________
Officially a member of the Itsacon fan club. Beer blasts are every friday at Viper_SB's house. I bring the chips. ![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > I Will Love You! Help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|