diamond asterisks

Mar 20, 2013 at 11:04pm
closed account (41U4izwU)
Hi, I am a beginner at c++. I am really stuck on this question and I really need help on it. I am trying to make diamond asterisks in c++. Here is the question: Write a program that prints the following diamond shape. You may use output statements that print either a single asterisk (*) or a single blank. Maximize your use of repetition ( with nested while or do/while structures) and minimize the number of output statements.

--*--
-***-
*****
-***-
--*--
This is the diamond. The dashes are meant to be spaces.
I really appreciate those who are willing to help me.
Mar 20, 2013 at 11:37pm
Please, this isn't a forum to let others do your homework.

The minimum you should have done yourself would be typing "diamond" into this forums search field at the top of this page.
Mar 20, 2013 at 11:43pm
closed account (41U4izwU)
I have, but I need my teacher wants me to do it with while loops and everything else that I have seen is out of the range that I am learning right now.
Mar 20, 2013 at 11:44pm
closed account (41U4izwU)
I've made a code, it's just I am using too many cout:

#include <iostream>
using namespace std;
int main()
{

int counter=1;
int counter2=1;
while (counter<=1) {
counter=counter+1;
cout<<" ";
cout<<"*"<<"\n";
}
cout<<" ";
while (counter2<=3){

counter2=counter2+1;
cout<<"*";

}



cout<<"\n";
int counter3=1;
while(counter3<=5){
counter3=counter3+1;
cout<<"*";
}
cout<<"\n"<<" ";

int counter4=1;
while(counter4<=3){
counter4=counter4+1;
cout<<"*";
}


int counter5=1;
while(counter5<=1){
counter5=counter5+1;
cout<<"\n"<<" ";
cout<<"*";
}


return 0; }


Last edited on Mar 20, 2013 at 11:46pm
Mar 21, 2013 at 12:39am
i change you code... but i hope you like it..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
using namespace std;
int main()
{
int i;

       for( i=0;i<3;i++)
       {
               for(int j=3;j>i;j--)
               cout<<" ";
                       for(int k=0;k<i;k++)
                       cout<<" *";
                       cout<<endl;
       }
       for(i=3;i>0;i--)
       {
               for(int j=3;j>i;j--)
               cout<<" ";
                       for(int k=0;k<i;k++)
                       cout<<" *";
                       cout<<endl;
                      
       }
       for(int i=0;i<3;i++)
       {
               for(int j=3;j>i;j--)
               cout<<" ";
                       for(int k=0;k<i;k++)
                       cout<<" *";
                       cout<<endl;
                       
        system("pause");
        return 0;
       } 
}
Last edited on Mar 21, 2013 at 12:39am
Mar 21, 2013 at 2:08pm
closed account (41U4izwU)
Thank you for your answer, by I have not learned the for loop yet, so I need to put it in a while loop.
Mar 21, 2013 at 4:09pm
closed account (41U4izwU)
I really need to answer this question as soon as possible, I would really appreciate it if someone was able to help me with it, using a while loop.
Mar 21, 2013 at 5:12pm
Topic archived. No new replies allowed.