Hello! Can somebody help me?
I'm reading C++ for Business Programming and there is a exercise asking for a program able to write the folowing:
X
XXX
XXXXX
XXXXXXX
XXXXXXXXX
XXXXXXXXXXX
XXX

Using nested loops someone can solve this?

Recommended Answers

All 6 Replies

Hello! Can somebody help me?
I'm reading C++ for Business Programming and there is a exercise asking for a program able to write the folowing:
X
XXX
XXXXX
XXXXXXX
XXXXXXXXX
XXXXXXXXXXX
XXX

Using nested loops someone can solve this?

Yes, many people can solve this. You need to use code tags and a constant font like Courier. Otherwise all the formatting is lost. All of these problems involve the same thing.

1. Set up the outer loop.
2. Set up an inner loop to display spaces.
3. Display the spaces.
4. Set up an inner loop to display X's.
5. Display the X's
6. Display a newline.
7. Go through outer loop again.

im compiling a website solely dedicated to John mullazos book which will have answers to all exercises, and dont worry there will be online help, not this quick to judge sentiments such as the previous persons remarks.

http://programmersguide.weebly.com/

the website is not currently up, but will be in a couple of days just check back in the next coming days.

in the meantime heres the one you requested

#include <iostream>
using namespace std;
#include <iomanip>

int main()
{

	char symbol = 'X';
	int k = 37;
	int j,i,m;


	m=k;
	for(int l=0; l<8; ++l)
		cout<<"\n";

	for(i=1; i<=11;i+=2)
	{
		cout<<endl;
	   --k;
	   cout<<setw(k);
		for(j = 0; j<i; ++j)
			cout<<symbol;
	}
	cout<<endl;
	m-=2;
	cout<<setw(m)<<symbol<<symbol<<symbol<<endl;




	return 0;

now look at it and go through each step as if your the computer, that way you will understand the way it works

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.