Guest User

Untitled

a guest
Jan 12th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. // Diamond Display
  2. // This program uses nested loops to display a diamond.
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int base=11;
  9. char symbol='*';
  10. int bcounter=1,rowcount=1;
  11. int toprows;
  12. int num=1;
  13. char answer;
  14.  
  15.  
  16.  
  17. cout<<"Enter a number for the base of the triangle and a character for the symbol"<<endl;
  18. cin>>base;
  19. cin>>symbol;
  20.  
  21. if(base%2==0)
  22. base++;
  23. //this code below generates the base of the triangle
  24. toprows=base/2;
  25.  
  26. int symbolcount=base;
  27. if(cin)
  28. {
  29. while(rowcount<=toprows)
  30. {
  31. int spacecount=rowcount;
  32. while(spacecount<=toprows)
  33. {
  34. cout<<' ';
  35. spacecount++;
  36.  
  37. }
  38.  
  39. while(symbolcount>=base&&symbolcount>0)
  40. {
  41.  
  42.  
  43. cout<<symbol;
  44.  
  45. symbolcount--;
  46. }
  47. num++;
  48. num++;
  49. symbolcount=symbolcount+num;
  50.  
  51.  
  52.  
  53.  
  54. cout<<endl;
  55. rowcount++;
  56. }
  57.  
  58.  
  59. while(bcounter<=base)
  60. {
  61. cout<<symbol;
  62. bcounter++;
  63. }
  64. toprows=base/2;
  65. char answer;
  66. cout<<"Would you like to quit the program? n for no q for quit"<<endl;
  67. cin>>answer;
  68. while(answer=='n')
  69. {
  70. symbolcount=base;
  71.  
  72. num=1;
  73. bcounter=1;
  74. }
  75. }
  76. //loops to generate top rows of triangle not including the base
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90. cout<<endl;
  91. system("PAUSE");
  92. return 0;
  93. }
Add Comment
Please, Sign In to add comment