Acii Tree

hi, Im trying to write a program that displays an upside down triangle.I'm only able to dispay a normal one. PLEASE HELP!!

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
  #include <iostream>



using namespace std;



void printStars(int blanks, int starsInLine);



int main() 

{

	
//Decleration of Variables
	
int noOfLines;
	
int counter;
	
int noOfdots;

	
	
//Prompting The User For Input
	
cout << "Enter the number of starred lines the triangle should have: " ;


//Storing User Input
	
cin >> noOfLines;

	
	
while (noOfLines < 0 || noOfLines > 20)
		
    {  
       cout <<"The number of lines should be between 1 and 20"<< endl;

       cout << "Enter the number of starred lines the triangle should have: " ;

       cin >> noOfLines;

    }


noOfdots = 30;
	
	
	
for ( counter=1 ; counter <=noOfLines; counter-- )
     {
			
      printStars(noOfdots, counter);
			
      noOfdots--;
		
     }

	

return 0;
}
	


void printStars(int dots, int starsInLine)

{
	
int count;
	
	
for (count = 1;  count <= dots; count--)             //Prints Number Of . Before Stars In A Line

      cout<<'.';
	
for(count = 1; count <= starsInLine; count ++)        //Prints Number Of Stars With Blanks Between
	
      cout << " *";
	
	
cout << endl;

}
Do you mean this shape?

*********
 ******* 
  *****  
   ***   
    *   


or more like


******
*****
**** 
***
**
*   
i also had the problem that i got unlimited - chars, because you dont give your variables a value, so dots and starsinlines gets a random bit pattern i think.

So i wanted to try to solve the problem and finally got the solution, a bit different than yours.
Do anybody knows if i these 4 for loops are nessesary? :)

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  #include <iostream>
 #include <string>
 using namespace std;



int main() 
{

//declaration of local variables:
int dots = 0;
bool direction = 0;
int fordots = 0;

cout << "how many lines of dots do you want ? (max 30)" << endl;
cin >> dots;

while (dots < 0 || dots >30)
	{
	cout << "invalid answer, please type again \n";
    cin >> dots;
	}

fordots = dots;

cout << "You want your triangle normal(0) or upsidedown?(1) ";
cin  >> direction;



if (direction == false)
{
	for (int i = 0; i <= dots; i++)
	{
				
		for (int j = 30; j >= i; j--)
		{
		cout << "-";
		}
		for (int k = 0; k <= i; k++)
		{
			cout<< "*";
		}
		for (int m = 1; m <=i; m++)
		{
			cout<< "*";
		}
		cout <<"\n";
	}
}
 else
 {
 	for (int i = 0; i <= dots; i++)
 	{
 		 		
 		 		
 		for (int j = 0; j <= i; j++)
 		{
 			cout << "-";
 		}
		for (int k = 0; k <= fordots; k++)
 		{
 			cout << "*";
 		}
 		for (int m = 1; m <= fordots; m++)
 		{
 			cout << "*";
 		}
 		
 		fordots--;
 		
 		cout <<"\n";
		
 	}
 }

}

return 0;
Last edited on
@wildblue the firdt one
@cydone your code works but i think the closing brace at the top of return should be at the bottom of return... thanks anyway
Topic archived. No new replies allowed.