help needed

This is a discussion on help needed within the C++ Programming forums, part of the General Programming Boards category; hi guys ...i can,t get to display dis an empty diamond using setw...i,ve written some ov the code..its incomplete..cant get ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    4

    help needed

    hi guys ...i can,t get to display dis an empty diamond using setw...i,ve written some ov the code..its incomplete..cant get any further..please help! i,ve to submit it in 6 hours.
    Code:
         
           *
        *    *
      *         *
    *              *
      *          *
        *     *
           *
    
    
        #include <iostream.h>
    #include <iomanip.h>
    int main()
    {
    	int a,b,c,d,e,x,y,z;
    	cout<<"enter no. of rows"<<endl;
    	cin>>a;
    	
    	
    	for (x=1; x<=a; x++)
    	{
    		cout<<setw(x)<<"*"<<endl;
    	}
    
         for (y=10; y>=a; y--)
    	 {
    		 cout<<setw(y)<<"*"<<endl;
    	 }
    
    		return 0;
    }
    Last edited by crazy_chick; 05-15-2007 at 11:56 AM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Unfortunately that code won't compile on my compiler, your header files are outdated and non-standard. If your class allows it you should switch to <iomanip> and <iostream>, and you'll have to add a using namespace std; line below the #includes.

    I also can't read your output since it is in code tags and all whitespace is lost. Can you post the output in code tags to maintain the whitespace?

    Finally, while you're waiting for an answer check out the forum rules and posting guidelines. Things like putting "urgent" in the subject and not using proper grammar and spelling tend to make people not want to help.

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    4
    ok i think you will be able to run it now .here is the code and output i get
    Code:
                *
                  *
                    *
                      *
                        *
                                *
                             *
                           *
                         *
                      *
    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    int main()
    {
    	int a,x,y;
    	cout<<"enter no. of rows"<<endl;
    	cin>>a;
    	
    	
    	for (x=1; x<=a; x++)
    	{
    		cout<<setw(x)<<"*"<<endl;
    	}
    
         for (y=10; y>=a; y--)
    	 {
    		 cout<<setw(y)<<"*"<<endl;
    	 }
    
    		return 0;
    }
    Last edited by crazy_chick; 05-15-2007 at 12:43 PM.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,594
    Notice that other than the first and last lines, you print two asterisks per line. You probably should use variable names that are more descriptive than a, b, c, d, e, x, y, z.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Look at the picture. Now imagine if you combined the two loops, it would look like the bottom half of the diamond (or at least close to it), right? See if you can combine the two to output two asterisks per line as laserlight suggested, and once you get the bottom half of the diamond you can figure out how to do the top half.

  6. #6
    Registered User
    Join Date
    May 2007
    Posts
    4

    Unhappy

    thats the problem .i can,t combine the two

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    >> thats the problem .i can,t combine the two
    How have you tried?

  8. #8
    Registered User
    Join Date
    May 2007
    Posts
    4
    offcourse i have tried .i told you i can,t get any further, i am a high school student,just a begginner

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    I said "How have you tried?" I know you tried, but the best way to get help is to make an attempt, and then post that attempt and ask specific questions about your attempt.

    So, show us your latest attempt to combine the two loops and output more than one asterisk per line. Also tell us how its not working.

  10. #10
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    Combine the loops as in to nest them so they work together
    I'm just trying to be a better person - My Name Is Earl

  11. #11
    Registered Abuser Loic's Avatar
    Join Date
    Mar 2007
    Location
    Sydney
    Posts
    115
    I would do that in one loop… something like
    Code:
    cout << setw(x) << "*" << setw(f) << "*" << endl;
    where x is the distance from the left side of the screen to the first * and f is the gap between the stars.

    And then just come up with an algorithm that increases the values (x & j) accordingly… and then decreases them
    Last edited by Loic; 05-16-2007 at 07:08 PM.

  12. #12
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Most C++ compilers don't like and . " is the proper character.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. free needed or not?
    By quantt in forum Linux Programming
    Replies: 3
    Last Post: 06-25-2009, 09:32 AM
  2. C Programmers needed for Direct Hire positions
    By canefan in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 09-24-2008, 11:55 AM
  3. lock needed in this scenario?
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-25-2008, 07:22 AM
  4. C++ help needed
    By Enkindu in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 08-31-2004, 11:24 PM
  5. semi-colon - where is it needed
    By kes103 in forum C++ Programming
    Replies: 8
    Last Post: 09-12-2003, 05:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21