fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void printpattern(int pattern_type, int pattern_size);//function call
  6.  
  7. int main()
  8. {
  9. int pattern_type;
  10. int pattern_size;
  11. char ans;
  12.  
  13. ans=='y';//this makes it loop until the uses enters a different character
  14.  
  15. while (ans=='y' || ans == 'Y')
  16. {
  17. cout << "Please enter pattern type.\n";
  18. cin >> pattern_type;
  19. cout << "Please enter a pattern size.\n";
  20. cin >> pattern_size;
  21.  
  22. printpattern(pattern_type, pattern_size);
  23.  
  24. cout << "Please enter Y or y to continue. Enter any other character to exit the program.\n";
  25. cin >> ans;
  26. }
  27.  
  28. return 0;
  29. }
  30.  
  31.  
  32. void printpattern(int pattern_type, int pattern_size)
  33. {
  34.  
  35. if(pattern_size > 10 || pattern_size < 1)
  36. {
  37. cout << "Pattern size should be between (1-10)\n";
  38. return;
  39. }
  40.  
  41. switch (pattern_type)
  42. {
  43.  
  44. case 1:
  45. for (int i=0; i < pattern_size; i++)
  46. {
  47. for (int j=0; j < pattern_size; j++)
  48. if (i==j)
  49. cout << "\t" << "$";
  50. else
  51. cout << ' ';
  52. cout << endl;
  53. }
  54. case 2:
  55. for (int i=0; i < pattern_size; i++)
  56. {
  57. for (int j=0; j < pattern_size; j++)
  58. if (j <= i)
  59. cout << "$";
  60. else
  61. cout << ' ';
  62.  
  63. cout << endl;
  64. }
  65. break;
  66. case 3:
  67. for (int i=0; i < pattern_size; i++)
  68. {
  69. for (int j=0; j < pattern_size; j++)
  70. if (j >= i)
  71. cout << "$";
  72. else
  73. cout << ' ';
  74. cout << endl;
  75. }
  76. break;
  77.  
  78. default:
  79. cout << "Pattern type should be between (1-3).\n";
  80. }
  81. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
Standard output is empty