Hi just a bit of direction please

Hi thanks for reading i have question to complete haveing a bit of trouble i am using VB 2010 and C++ the Question is:

Exercise 5: Pattern generation using loops
Write two C++ functions to generate the following patterns using nested looping techniques and call the functions in the main program.

StarPattern()
. * * * * * * *
* . * * * * * *
* * . * * * * *
* * * . * * * *
* * * * . * * *
* * * * * . * *
* * * * * * . *
* * * * * * * .



DotPattern()
.
. .
. . .
. . . .
. . . . .
. . . . . .
. . . . . . .
. . . . . . . .
I have the code for the dot pattern as follows

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;

void printline(void); 



 int main() 
{  

  char prnt = '*';
  

  int i, j, nos = 0, s;  

	for (i = 1; i !=8; i++) 
	{  

	 for (s = nos; s >= 1; s--)
	
	{   

   printf("  ");  

	}  

	for (j = 1; j <= i; j++) 
	{  

	printf("%2c", prnt);  

	}  

	printf("\n");  

		nos;   // Controls the spacing factor  

}  

	return 0;  

}


my problem is i don't know where to start with the other star pattern please could someone point me in the write direction. thanks all
Well here is a hint for your star pattern problem:

1. You are printing the same number of columns on each row unlike your other pattern problem.
2. If the column number matches row number, you will print a different character for that column.
i am not asking for the code just even different code not relating to mine that gives me an idea i am really new this and barly understand how that code wrote works could please explain a bit more on how to do that or where could read up on that sort of stuff please
I will explain the logic for dot pattern. Follow the same for the star pattern.

Requirements
1. You need to print 8 rows of dots.
2. However, each row should have only that many number of dots as the row number. In other words, row 1 will have 1 dot and row 2 will have 2 dots and row 3 will have 3 and so on.

Pseudo code
1
2
3
4
Step 1: For rows = 1 to 8
Step 2:     For columns = 1 to rows //Because of requirement 2 above
Step 3:         print (1 dot character)
Step 4:     print a newline character to go to the next row


C++ Implementation
1. For steps 1 and 2, use a for loop
2. For step 3, use cout << '.' for printing the dot character.
3. For step 4, use cout << endl for printing the new line character.

I hope with this pseudo code combined with a little bit of learning, you will be able to complete both the patterns. Good Luck.
Last edited on
thanks very much cheers i will try to get my head around it
Topic archived. No new replies allowed.