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

How to generate a program in C++ that gives the output as follows - consider as dash. ----* ---*** --***** -******* *********

OpenStudy (anonymous):

using a loop?

OpenStudy (anonymous):

cout << "----*\n---***\n--*****\n-*******\n*********" << endl;

OpenStudy (anonymous):

Use a for loop, or maybe a nestled for loop. You start with 4 underscores and decrement by one on each line. You add two asterisks on each line. Start the problem, post any further questions/problems you have.

OpenStudy (anonymous):

You should use a loop

OpenStudy (anonymous):

There are many ways to do this, one of them is to store the content of each line in array/vector of strings and then perform the following code: copy(strTable.begin(), strTable.end(), ostream_iterator<string> (cout, "\n")) // vector version or: copy(strTable, strTable+size, ostream_iterator<string> (cout, "\n")) // array version -- you have to know how many elements you have

OpenStudy (anonymous):

for (int i=0; i<5; i++) { for (int j=0; j<4; j++) { if (j < 4-i) cout << "-"; else cout << "**"; } cout << "*" << endl; }

OpenStudy (anonymous):

Well, I, for one, think that providing a ready-made program as an answer to a question like this is not very helpful. Being able to copy&paste is not a skill you want to instill. Now, to the question itself: 1) Do you know how to output characters in C++? 2) Do you know how to use variables and loops? 3) What can you tell about the number of '-' and '*' characters in each row? How do they change? If you can answer these questions, you should be able to write your own program. Good luck!

OpenStudy (anonymous):

Wops... I agree... I wrote it without actually thinking about it, but you're right.

OpenStudy (anonymous):

u need to use for loop 3 times ,one for the space, one for the stars, and one for the rows

OpenStudy (anonymous):

great, now try generating this: |*----| |-*---| |--*--| |---*-| |----*| |---*-| |--*--| |-*---| |*----| |-*---| ...

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!