fork(2) 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. const char SPACE = ' ', PATTERN = '$';
  13.  
  14. ans=='y';//ans always y so continues to loop unless n
  15.  
  16. while (ans=='y' || ans == 'Y')
  17. {
  18. cout << "Please enter pattern type.\n";
  19. cin >> pattern_type;
  20. cout << "Please enter a pattern size.\n";
  21. cin >> pattern_size;
  22.  
  23. printpattern(pattern_type, pattern_size);
  24.  
  25. cout << "Please enter Y or y to continue. Enter any other character to exit the program.\n";
  26. cin >> ans;
  27. }
  28.  
  29. return 0;
  30. }
  31.  
  32.  
  33. void printpattern(int pattern_type, int pattern_size)
  34. {
  35.  
  36. if(pattern_size > 10 || pattern_size < 1)
  37. {
  38. cout << "Pattern size should be between (1-10)\n";
  39. return;
  40. }
  41.  
  42. switch (pattern_type)
  43. {
  44.  
  45. case 1:
  46. for (int i=0; i < pattern_size; i++)
  47. {
  48. for (int j=0; j < pattern_size; j++)
  49. if (i==j)
  50. cout << "\t" << "$";
  51. else
  52. cout << ' ';
  53. cout << endl;
  54.  
  55. case 2:
  56. for (int i=0; i < pattern_size; i++)
  57. {
  58. for (int j=0; j < pattern_size; j++)
  59. if (j <= i)
  60. cout << "$";
  61. else
  62. cout << ' ';
  63.  
  64. cout << endl;
  65. }
  66. break;
  67. case 3:
  68. for (int i=0; i < pattern_size; i++)
  69. {
  70. for (int j=0; j < pattern_size; j++)
  71. if (j >= i)
  72. cout << "$";
  73. else
  74. cout << ' ';
  75. cout << endl;
  76. }
  77. break;
  78.  
  79. default:
  80. cout << "Pattern type should be between (1-3).\n";
  81. }
  82. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'void printpattern(int, int)':
prog.cpp:55:6: error: jump to case label [-fpermissive]
 case 2:
      ^
prog.cpp:46:10: error:   crosses initialization of 'int i'
 for (int i=0; i < pattern_size; i++)
          ^
prog.cpp:67:6: error: jump to case label [-fpermissive]
 case 3:
      ^
prog.cpp:46:10: error:   crosses initialization of 'int i'
 for (int i=0; i < pattern_size; i++)
          ^
prog.cpp:79:1: error: jump to case label [-fpermissive]
 default:
 ^
prog.cpp:46:10: error:   crosses initialization of 'int i'
 for (int i=0; i < pattern_size; i++)
          ^
prog.cpp:82:1: error: expected '}' at end of input
 }
 ^
stdout
Standard output is empty