For loops to create four right triangle histograms...HELP!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • simpleeshelbee
    New Member
    • Nov 2006
    • 16

    For loops to create four right triangle histograms...HELP!!

    Hey all,
    This is my first post. I am really hoping that someone out there has a solution to my C++ coding problem...

    This is my code and what I have to do...
    I think it is rows of 1 - 10 and then back

    *************** *************** *************** *************** *************** *************** **

    //These histograms are supposed to print beside eachother like this:

    //* *************** ***** *
    //** ********* ********* **
    //*** ******** ******** ***
    //**** ******* ******* ****
    //***** ****** ****** *****
    //****** ***** ***** ******
    //******* **** **** *******
    //******** *** *** ********
    //********* ** ** *********
    //*********** ***********
    //but I can't make them go beside eachother. My code below makes two of them,
    //but they are one under the other!! Not what I need....

    //HELP??????



    #include <iostream>
    using namespace std;

    int count;


    main()
    {



    for(int count_1=1;count _1<=10;count_1+ +)
    {
    for(int count_2=1;count _2<=count_1;cou nt_2++)
    cout<<"*";

    cout<<endl;
    }

    cout << "\n";

    for(int count_3=1;count _3<=10;count_3+ +)
    {
    for(int count_4=10;coun t_4>=count_3;co unt_4--)
    cout<<"*";

    cout<<endl;

    }


    cout << "\nPress q and then Enter to quit-->"; //
    char dummy;
    cin >> dummy; //Wait for input
    return 0;

    } // main
    *************** *************** *************** *************** *************** *************** *

    Help anyone, please!!!!!!!

    Thanks,
    Shelbee
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    This line

    cout<<endl;

    and this line

    cout << "\n";

    are equivilent and moves the output onto a new line.

    If you don't want to start on a new line then don't run this line of code.

    Comment

    • simpleeshelbee
      New Member
      • Nov 2006
      • 16

      #3
      Hey,
      Thanks for responding.

      I tried that, just now again, and then it runs one of the triangles and the other is all on the first line in one long line of asterisks...! LOL It's making me crazy!! I thought about pulling my hair out, but I would look funny!! LOL HELP...?

      Stuck again...?

      Shelbee

      Comment

      • luninspectra
        New Member
        • Nov 2006
        • 6

        #4
        If you think about it, you can't add lines to what you already outputted. What I believe you're trying to do is add the triangles to what you've already outputted.

        I believe what you are doing is equivalent to trying to do this:

        cout << "super";
        cout << endl;
        cout << "man";

        and you're expecting superman, yet you get super/man.

        I think your whole algorithm needs refining. Let me see what I can do, I'll get back to you.

        Comment

        • luninspectra
          New Member
          • Nov 2006
          • 6

          #5
          I have refined the source code for you, its probably not exact, but the output is this:

          -bash-3.00$ a.out
          * ********** ********** *
          ** ********* ********* **
          *** ******** ******** ***
          **** ******* ******* ****
          ***** ****** ****** *****
          ****** ***** ***** ******
          ******* **** **** *******
          ******** *** *** ********
          ********* ** ** *********
          ********** * * **********


          Press q and then Enter to quit-->q
          -bash-3.00$

          Here's the refined source code:

          //These histograms are supposed to print beside eachother like this:
          //* ********** ********** *
          //** ********* ********* **
          //*** ******** ******** ***
          //**** ******* ******* ****
          //***** ****** ****** *****
          //****** ***** ***** ******
          //******* **** **** *******
          //******** *** *** ********
          //********* ** ** *********
          //*********** ***********
          //but I can't make them go beside eachother. My code below makes two of them,
          //but they are one under the other!! Not what I need....
          //HELP??????



          #include <iostream>
          using namespace std;


          int count;

          int main() {

          for(int stars = 1; stars <= 10; stars++) {
          for(int count = 1; count <= stars; count++) {
          //It'll print the amount of stars
          cout << "*";
          if(count == stars)
          cout << " ";
          }

          for(int count_2 = 10; count_2 >= stars; count_2--) {
          cout << "*";
          if(count_2 == stars)
          cout << " ";
          }

          for(int count_2 = 10; count_2 >= stars; count_2--) {
          cout << "*";
          if(count_2 == stars)
          cout << " ";
          }

          for(int count = 1; count <= stars; count++) {
          cout << "*";
          if(count == stars)
          cout << " ";
          }


          cout << endl;
          }

          cout << "\n";

          cout << "\nPress q and then Enter to quit-->"; //
          char dummy;
          cin >> dummy; //Wait for input

          return 0;

          }


          Hope ya like it ;).

          Comment

          • simpleeshelbee
            New Member
            • Nov 2006
            • 16

            #6
            Hey!!

            Thanks so much! The code was great...except that I need the two middle triangles turned the other way. I will try and look at your code to see what is needed to turn them around, but your code has come closer than anything I could figure out!!

            In the diagram that I have here, the two middle right triangles are supposed to have their straight sides facing the other way. So, the straight side of triangle two should face triangle one, and the straight side of triangle three should face triangle four. Make sense? I hope you can fix it because I don't know if I can...LOL.

            Thanks so much and will be checking back often to see your response!! :)
            Shelbee

            Comment

            • simpleeshelbee
              New Member
              • Nov 2006
              • 16

              #7
              More Help !!!!????

              PLEASE??

              Shelbee

              Comment

              • luninspectra
                New Member
                • Nov 2006
                • 6

                #8
                Can you draw what you mean? I don't understand what you mean by having the two middle triangles facing the other way...I'll see what I can do once you aid me visually :).

                Comment

                • simpleeshelbee
                  New Member
                  • Nov 2006
                  • 16

                  #9
                  Hey there!

                  Sure I will try to draw it here...(the last time that I drew it, it didn't leave enough space between the four triangles, LOL)

                  * *************** ***** *
                  ** ********* ********* **
                  *** ******** ******** ***
                  **** ******* ******* ****
                  ***** ****** ****** *****
                  ****** ***** ***** ******
                  ******* **** **** *******
                  ******** *** *** ********
                  ********* ** ** *********
                  *********** ***********


                  Hope it stays the same when I post this...

                  Thanks so much!
                  Shelbee

                  Comment

                  • simpleeshelbee
                    New Member
                    • Nov 2006
                    • 16

                    #10
                    It didn't...
                    I am going to put it on here with letters instead, for display purposes, but I still need the results in asterisks and spaces.
                    So, the "a" will stand for the asterisks and the "p" will be spaces. The asterisks are in sets of 10.

                    apppppppppaaaaa aaaaaaaaaaaaaaa pppppppppa
                    aappppppppaaaaa aaaappaaaaaaaaa ppppppppaa
                    aaapppppppaaaaa aaappppaaaaaaaa pppppppaaa
                    aaaappppppaaaaa aappppppaaaaaaa ppppppaaaa
                    aaaaapppppaaaaa appppppppaaaaaa pppppaaaaa
                    aaaaaappppaaaaa ppppppppppaaaaa ppppaaaaaa
                    aaaaaaapppaaaap pppppppppppaaaa pppaaaaaaa
                    aaaaaaaappaaapp ppppppppppppaaa ppaaaaaaaa
                    aaaaaaaaapaappp pppppppppppppaa paaaaaaaaa
                    aaaaaaaaaaapppp ppppppppppppppa aaaaaaaaaa


                    Now, I will go line for line in words to explain what happened up there...LOL.
                    1st line - 1 'a', 9 'p', 10 'a', 10 'a', 9 'p', 1 'a'
                    2nd line- 2 'a', 8 'p', 9 'a', 1 'p', 1 'p', 9 'a', 8 'p', 2 'a'
                    3rd line - 3 'a', 7 'p', 8 'a', 2 'p', 2 'p', 8 'a', 7 'p', 3 'a'
                    etc....


                    Does that help? It messes up the view each time I try to post it with spaces instead of letters.
                    Thanks so much!!
                    Shelbee

                    Comment

                    • simpleeshelbee
                      New Member
                      • Nov 2006
                      • 16

                      #11
                      Was wondering if that last post helped any with visualizing what I need?

                      Thanks,
                      Shelbee

                      Comment

                      • simpleeshelbee
                        New Member
                        • Nov 2006
                        • 16

                        #12
                        Hey there! Just wanted to see if I was still remembered? Still need that code...? I was getting too far back on the board and thought maybe "outta sight, outta mind", LOL. Waiting to hear back from ya!

                        Thanks,
                        Shelbee

                        Comment

                        • simpleeshelbee
                          New Member
                          • Nov 2006
                          • 16

                          #13
                          Feel like I have been forgotten. Can anyone help me with this code? I really NEED it...like rightaway...

                          Thanks,
                          Shelbee

                          Comment

                          • simpleeshelbee
                            New Member
                            • Nov 2006
                            • 16

                            #14
                            Hey guys,
                            Can anyone turn those inside two triangles around? The best code I have, I got from here, but it has the inside two triangles' straight sides facing eachother when they should be facing the other way..?

                            Anyone? Please help...

                            Thanks,
                            Shelbee

                            Comment

                            • simpleeshelbee
                              New Member
                              • Nov 2006
                              • 16

                              #15
                              Still waiting to hear back about the loops...? Can anyone help me? I really need to figure out how to switch those triangles around that are in the middle...? Anyone??

                              Thanks,
                              Shelbee

                              Comment

                              Working...