Answer» Hello I have a problem I have to make a triangle that look like this ***** **** *** ** *
I create the program for the triangle that look like this
* ** *** **** *****
The program that I have for that triangle is #include using namespace sd;
void mai () { int i=0; while (i<10) { int j=10; while (j>=i) { COUT<<"*"; j--; } j=0; while (j<=i) { cout<<"*"; j++; } cout<i++; } }
Can somebody show me or help me to fix this one so it would look like the first triangle figure
PleaseYou only need one loop...
make "i" for EXAMPLE, go from 1 to 5, and output 5-i spaces and i asterisks for each iteration.I am sorry I am really new ith c++ could you show me how to corrected in my code please.we don't DO homework for you.
However I will give you VB code. that way at least you'll need to do some work to convert it.
Code: [Select]Dim I as Integer For I = 1 to 5 Print Space$(5-i) + STRING$(i,"*") Next I Is this what you want?
#include #include using namespace std;
int main() { int i = 0; int j = 5; while (j > 0) { while (i < j) { cout << "*"; ++i; } cout << endl; i = 0; --j; } system("pause"); return 0; }What is it with PEOPLE and While() loops? for() loops were designed for a reason...
Code: [Select]#include <stdio.h> #include <iostream.h>
int main(int argc, char* argv[]) {
for(int i=1;i<=5;i++) { for (int j=i+1;j<=5;j++) cout << " ";
for (j=i;j>0;j--) cout << "*";
cout << endl;
}
getchar(); return 0; } I'm sure we get asked how to do C++ triangles at least once a month. I know. It is almost surely some form of assignment somewhere.
Normally I don't like helping people fail courses but if they're going to be given an answer it's probably best for it to be completely in C/C++ and DONE with the more appropriate control structures. This way at least they can fail admirably, or something.
|