This is what I need to do and I can only use loops. However we need to ask for t
ID: 3534037 • Letter: T
Question
This is what I need to do and I can only use loops. However we need to ask for the number of + but I dont know how to print the spacce or right justified
http://www.chegg.com/homework-help/starting-out-with-c-plus-plus-from-control-structures-through-objects-brief-edition-7th-edition-chapter-5-problem-23pc-solution-9780132772891
#include<iostream>
#include<iomanip>
using namespace std;
//start main function
int main()
{
int number;
cout << "Please enter a number between 1 and 20 " << endl;
cin >> number;
//display the table heading
cout << "---------------------------------------------------" << endl;
cout << "Patter A Pattern B" << endl;
cout << "---------------------------------------------------" << endl;
//outer loop to maintain the number of lines
for (int i=0; i < number; i++)
{
//inner loop to display plus sing in Pattern A
for (int j=0; j <= i; j++)
{
cout << "+";
}
//inneer loop to display the spaces using tab character (' ')
//between Pattern A and Pattern B
if((i==number-1 || i==number-2 || i==number-3))
{
cout << " ";
}
else
{
cout << " ";
}
//Loop to dispaly plus signs in Pattern B
for(int j = number; j>i; j--)
{
cout << "+";
}
cout << endl; // go to the next line
}// end of outer loop
cout << "-------------------------------------------------" << endl;
//pause the system for a while
system("pause");
return 0;
}//end of main function
Explanation / Answer
//right justified http://ideone.com/Sd4XJK
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.