loops

Hi all i am using visual studio 10 also am using c++

i need to out put the following pattern:

. * * * * * * *
* . * * * * * *
* * . * * * * *
* * * . * * * *
* * * * . * * *
* * * * * . * *
* * * * * * . *
* * * * * * * .
by the way the dot are on the same lines as the stars

this is my code it just prints a soild block of stars no dots on any of the lines any ideas please
My code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <stdio.h>
using namespace std;

 int main()
{
	char star = '*';
	char dot = '.';
	int i,j,k, lines= 7, columns = 7, dotOnLines;

	for  ( i = 0; i < lines; i++)// this is to print 7 lines down 
	{
	for (j= 0; j < columns; j++)// this is to print 7 columns across
	
	{
			cout<< star;
	}
		for (k=0 ; k == i && i == j; k++) // This is to print dots diagonally down the middle
	{
		cout<< dot;
	}
	cout<<endl;
	
	}
	return 0 ;
}
It's a simple line equation.
 0 1 2 3 4 5 6 7
0. * * * * * * *
1* . * * * * * *
2* * . * * * * *
3* * * . * * * *
4* * * * . * * *
5* * * * * . * *
6* * * * * * . *
7* * * * * * * .

j is on x axis, i is on y axis. Can you see the relation between them?
#include <iostream>
using namespace std;


int main ()
{
for (int i = 0; i <= 7; i++)
{
for (int j = 0; j <= 7; j++)
{
if (i == j)

cout << ".";


else

cout << "*";

}//end inner loop
cout << endl;
}//end outer loop
return 0;
}

you just need to use the if statement to get the dots... hope this helps:)
Topic archived. No new replies allowed.