Ask your own question, for FREE!
Computer Science 17 Online
OpenStudy (anonymous):

loop program to display this: Enter height: 5 * * * * * * * * *

OpenStudy (anonymous):

what do you have so far?

OpenStudy (anonymous):

I think I know the answer ;)

OpenStudy (anonymous):

i have this, it's different, i can't seem to change the loop statement :( #include <iostream.h> #include <conio.h> int main() { int number=0; int counter1=0; cout<<"Enter the size of the shape: "; cin >> number; counter1=-number; while(counter1 <=number) { for (int counter2 = -number; counter2 <= number; ++counter2) { if (abs(counter1) == abs(counter2)) { cout<<"x"; } else { cout<<" "; } } ++counter1; cout<<endl; } getche (); return 0; }

OpenStudy (anonymous):

have you tried drawing it out with a regular pen and paper for these cases? : height = 1, 2,3 ?

OpenStudy (anonymous):

yup, for example when i enter 3 x x x x x x x x x x x x x

OpenStudy (anonymous):

i got a new set of codes, but still not working, i can't figure out what is wrong :( #include <iostream.h> #include <math.h> #include <conio.h> int main() { int num, length; clrscr(); cout<<"Enter the size: "; cin >> length; num=length for(int i=1; i<length; i++) { for(int j=1; j<length; j++) { if((i==j) && (j==num)) cout<<"*"; else cout<<" "; } num--; cout<<endl; } getche (); return 0; }

OpenStudy (anonymous):

^ tl;dr summary : think about it some more... work it out with pen and paper on what the computer is actually doing.

ganeshie8 (ganeshie8):

try this : #include <iostream.h> #include <conio.h> int main() { int number=0; int counter1=0; cout<<"Enter the size of the shape: "; cin >> number; counter1=-number\(/2\); while(counter1 <=number) { for (int counter2 = -number\(/2\); counter2 <= number\(/2\); ++counter2) { if (abs(counter1) == abs(counter2)) { cout<<"x"; } else { cout<<" "; } } ++counter1; cout<<endl; } getche (); return 0; }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!