Hello daniweb people! I'm having a few issues with this triangle program. We're supposed to make a few different triangle shapes, including the two i have in this. The first triangle works, but the second triangle displays xxxxxxxxxxxxxxx times infinity. Any ideas on what i'm doing wrong? And another question, how would I get started with part of this program to also make a diamond shape given a certain Row size input? thanks!

#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;
int main()
{
// make triangle 
// X
// XX
// XXX
// XXXX
// XXXXX
// XXXXXX
int rowSize;
cout << "Please enter the number of rows between 3 and 6 for a triangle: ";
cin >> rowSize;
for (int r=0;r<rowSize;r++)
{
	for(int c=0;c<r+1;c++)
	{
		cout << "*";
	}
	cout << endl;
}


{ 
	// Make triangle shaped different like so:
	// ******
	// *****
	// ****
	// ***
	// **
	// *
	int rowSize;
	cout << "Please enter another row size for a different triangle: ";
	cin  >> rowSize;
	for (int r=0;r<rowSize;r++)
	{
	for (int c=0;c<r-1;c--)
	{
		cout << "*";
	}
	cout << endl;
	}
	system("pause");
return 0;
}
}

Edited 5 Years Ago by Jared1337: Found one problem already

but the second triangle displays xxxxxxxxxxxxxxx times infinity.

if you have infinity in looping in your source code, then you should check
termination conditions in your code.

for (int c=0;c<r-1;c--)

so check this termination condition.

when r=0 it terminates.
when r=1 it terminates.
when r=2 it does not terminate......

This article has been dead for over six months. Start a new discussion instead.