Problems with for and while

I'm trying to creat a programm that draw two triangle like this:
[Enter the width of the triangle :7

[*******
*****
***
*
*
***
*****
*******]
The wildh is choosen by the user. Here is what I did :
The first triangle is working but the second no. (Sorry it is in french but Largeur means width)



#include <iostream>
#include <string>
#include <iomanip>

using namespace std;
int main()

{
int largeur = 0;

do {
cout << "Entrer la largueur: ";
cin >> largeur;
}while (largeur <= 3 || largeur % 2 ==0);

int nombreDEspacesT1 = 1;
int largeurT1= largeur;


//triangle1
while (largeurT1 > 0)

{
{for (int i = largeurT1; i > 0; i = i - 1) {
cout << "*";

} largeurT1=largeurT1-2;
cout << endl;

for (int espace = 1; espace <= nombreDEspacesT1; espace = espace + 1)
{
cout << " ";
}
nombreDEspacesT1 = nombreDEspacesT1 + 1;
}

}//end while triangle 1

cout<< largeur<<endl;




int largeurT2=1;
int espacement=largeur/2;


//while triangle2
while (largeurT2<=largeur){

{for (int j = largeurT2; j <largeurT2; j++) {
cout << "*" ;
}
cout << endl;
for (int espace2 = espacement; espace2 >=0; espace2--) {
cout << " ";
}

largeurT2 + 2 = largeurT2;

}//end for triangle 2

}// end while triangle 2


}//end main][/code]

I really need help,

Thanks

Last edited on
Topic archived. No new replies allowed.