943,166 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 274
  • C++ RSS
Feb 8th, 2010
0

Can I increament the Space?

Expand Post »
My only problem is the spacing..... to make it right.... i need to make it inverted pyramid pattern...
like this:
C++ Syntax (Toggle Plain Text)
  1.  
  2. 9 8 7 6 5 4 3 2 1
  3. 9 8 7 6 5 4 3 2
  4. 9 8 7 6 5 4 3
  5. 9 8 7 6 5 4
  6. 9 8 7 6 5
  7. 9 8 7 6
  8. 9 8 7
  9. 9 8
  10. 9

C++ Syntax (Toggle Plain Text)
  1. #include <iostream.h>
  2. #include <string.h>
  3. #include <conio.h>
  4. main()
  5. {
  6. clrscr();
  7. int num,n;
  8. cout<<"enter:";
  9. cin>>n;
  10. num=0;
  11. while (num !=n)
  12. {
  13. for(int i = n; i > num;--i)
  14. {
  15. cout << " " << i;
  16. }
  17. cout << endl<<" ";
  18. if(num == 0)
  19. cout<<" ";
  20. ++num;
  21. }
  22. getch();
  23. }
  24.  
  25. this is my code and only thing that wrong is the spacing before the rows...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
khevz09 is offline Offline
7 posts
since Jan 2010
Feb 8th, 2010
0
Re: Can I increament the Space?
Use an outer while loop to control the number of line. Within the outer while loop use two loops in sequential manner. The first inner loop will control the number of spaces to print for the line you are on. The second inner loop will print the sequence of numbers necessary for the line you are on.
C++ Syntax (Toggle Plain Text)
  1. line loop
  2. space loop
  3. numbers loop
Last edited by Lerner; Feb 8th, 2010 at 10:55 am.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005
Feb 8th, 2010
0
Re: Can I increament the Space?
Click to Expand / Collapse  Quote originally posted by khevz09 ...
My only problem is the spacing..... to make it right.... i need to make it inverted pyramid pattern...
like this:
this is my code and only thing that wrong is the spacing before the rows...

If I have understood you correctly you have an unwanted space at
the start of each line and that comes from your for loop.

Click to Expand / Collapse  Quote originally posted by khevz09 ...
C++ Syntax (Toggle Plain Text)
  1. #include <iostream.h>
  2. #include <string.h>
  3. #include <conio.h>
  4. main()
  5. {
  6. clrscr();
  7. int num,n;
  8. cout<<"enter:";
  9. cin>>n;
  10. num=0;
  11. while (num !=n)
  12. {
  13. for(int i = n; i > num;--i)
  14. {
  15. cout << " " << i;
You are outputting the first space here
if you:
C++ Syntax (Toggle Plain Text)
  1. //although cout << i << " "; should work
  2. cout << i;
  3. if(i != num + 1)
  4. {
  5. cout << " ";
  6. }

other spaces might want adjusting too
Reputation Points: 32
Solved Threads: 37
Junior Poster
tetron is offline Offline
199 posts
since Feb 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: how to send keystrokes to an arbitrary application?
Next Thread in C++ Forum Timeline: header file problem...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC