This is the code so far #include // for cin and cout #include // for setw() and setfill() using namespace std; // so that we don't need to preface every cin and cout with std:: void printSpaces(int n, int end) { for (int j = n; j > end; j--) { cout << " "; } } void printFirstTwoBuildingSection(int n, int startSpacing) { int start = 2 * ((n / 2) - 1), end = 0; for (int i = 0; i < n; i++) { printSpaces(startSpacing, 0); cout << "|"; if (i < (n / 2)) { printSpaces(i, 0); cout << "\\"; printSpaces(start, 0); cout << "/"; start -= (2); printSpaces(i, 0); cout << "|" << endl; } else { printSpaces(n - i - 1, 0); cout << "/"; printSpaces(end, 0); cout << "\\"; end += (2); printSpaces(n - i - 1, 0); cout << "|" << endl; } } printSpaces(startSpacing, 0); cout << "/"; for (int i = 0; i < n; i++) { cout << "-"; } cout << "\\" << endl; } int main() { int menuOption = 0; cout << "Choose from among the following options:\n" << "1. Exit the program\n" << "2. Display building\n" << "Your choice -> "; cin >> menuOption; cout << endl; // Leave a blank line after getting the user input for the menu option. // See if exit was chosen if (menuOption == 1) { exit(0); } // Menu 2 if (menuOption == 2) { int sections; cout << "Number of building sections -> "; cin >> sections; int n = 1 - (sections - 2) + sections * 2; int sizeOfBuild = 2; cout << setw(n) << " /\\ " << endl; cout << setw(n) << " || " << endl; cout << setw(n) << " || " << endl; cout << setw(n) << " -- " << endl; cout << setw(n) << "|++|" << endl; cout << setw(n) << "====" << endl; for (int i = 1; i <= sections; i++, sizeOfBuild += 2) { printFirstTwoBuildingSection(sizeOfBuild, sections - i); } } cout << endl; return 0; }
This is the code so far
#include <iostream> // for cin and cout
#include <iomanip> // for setw() and setfill()
using namespace std; // so that we don't need to preface every cin and cout with std::
void printSpaces(int n, int end)
{
for (int j = n; j > end; j--)
{
cout << " ";
}
}
void printFirstTwoBuildingSection(int n, int startSpacing)
{
int start = 2 * ((n / 2) - 1), end = 0;
for (int i = 0; i < n; i++)
{
printSpaces(startSpacing, 0);
cout << "|";
if (i < (n / 2))
{
printSpaces(i, 0);
cout << "\\";
printSpaces(start, 0);
cout << "/";
start -= (2);
printSpaces(i, 0);
cout << "|" << endl;
}
else
{
printSpaces(n - i - 1, 0);
cout << "/";
printSpaces(end, 0);
cout << "\\";
end += (2);
printSpaces(n - i - 1, 0);
cout << "|" << endl;
}
}
printSpaces(startSpacing, 0);
cout << "/";
for (int i = 0; i < n; i++)
{
cout << "-";
}
cout << "\\" << endl;
}
int main()
{
int menuOption = 0;
cout << "Choose from among the following options:\n"
<< "1. Exit the program\n"
<< "2. Display building\n"
<< "Your choice -> ";
cin >> menuOption;
cout << endl; // Leave a blank line after getting the user input for the menu option.
// See if exit was chosen
if (menuOption == 1)
{
exit(0);
}
// Menu 2
if (menuOption == 2)
{
int sections;
cout << "Number of building sections -> ";
cin >> sections;
int n = 1 - (sections - 2) + sections * 2;
int sizeOfBuild = 2;
cout << setw(n) << " /\\ " << endl;
cout << setw(n) << " || " << endl;
cout << setw(n) << " || " << endl;
cout << setw(n) << " -- " << endl;
cout << setw(n) << "|++|" << endl;
cout << setw(n) << "====" << endl;
for (int i = 1; i <= sections; i++, sizeOfBuild += 2)
{
printFirstTwoBuildingSection(sizeOfBuild, sections - i);
}
}
cout << endl;
return 0;
}


Step by step
Solved in 2 steps with 1 images









