#include <iostream>
using namespace std;
void printpattern( int pattern_type, int pattern_size) ; //function call
int main( )
{
int pattern_type;
int pattern_size;
char ans;
const char SPACE = ' ' , PATTERN = '$' ;
ans== 'y' ; //ans always y so continues to loop unless n
while ( ans== 'y' || ans == 'Y' )
{
cout << "Please enter pattern type.\n " ;
cin >> pattern_type;
cout << "Please enter a pattern size.\n " ;
cin >> pattern_size;
printpattern( pattern_type, pattern_size) ;
cout << "Please enter Y or y to continue. Enter any other character to exit the program.\n " ;
cin >> ans;
}
return 0 ;
}
void printpattern( int pattern_type, int pattern_size)
{
if ( pattern_size > 10 || pattern_size < 1 )
{
cout << "Pattern size should be between (1-10)\n " ;
return ;
}
switch ( pattern_type)
{
case 1 :
for ( int i= 0 ; i < pattern_size; i++ )
{
for ( int j= 0 ; j < pattern_size; j++ )
if ( i== j)
cout << "\t " << "$" ;
else
cout << ' ' ;
cout << endl;
case 2 :
for ( int i= 0 ; i < pattern_size; i++ )
{
for ( int j= 0 ; j < pattern_size; j++ )
if ( j <= i)
cout << "$" ;
else
cout << ' ' ;
cout << endl;
}
break ;
case 3 :
for ( int i= 0 ; i < pattern_size; i++ )
{
for ( int j= 0 ; j < pattern_size; j++ )
if ( j >= i)
cout << "$" ;
else
cout << ' ' ;
cout << endl;
}
break ;
default :
cout << "Pattern type should be between (1-3).\n " ;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnZvaWQgcHJpbnRwYXR0ZXJuKGludCBwYXR0ZXJuX3R5cGUsIGludCBwYXR0ZXJuX3NpemUpOy8vZnVuY3Rpb24gY2FsbAoKaW50IG1haW4oKQp7CmludCBwYXR0ZXJuX3R5cGU7CmludCBwYXR0ZXJuX3NpemU7CmNoYXIgYW5zOwpjb25zdCBjaGFyIFNQQUNFID0gJyAnLCBQQVRURVJOID0gJyQnOwoKYW5zPT0neSc7Ly9hbnMgYWx3YXlzIHkgc28gY29udGludWVzIHRvIGxvb3AgdW5sZ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0KYnJlYWs7CmNhc2UgMzoKZm9yIChpbnQgaT0wOyBpIDwgcGF0dGVybl9zaXplOyBpKyspCnsKZm9yIChpbnQgaj0wOyBqIDwgcGF0dGVybl9zaXplOyBqKyspCmlmIChqID49IGkpCmNvdXQgPDwgIiQiOwplbHNlCmNvdXQgPDwgJyAnOwpjb3V0IDw8IGVuZGw7Cn0KYnJlYWs7CgpkZWZhdWx0Ogpjb3V0IDw8ICJQYXR0ZXJuIHR5cGUgc2hvdWxkIGJlIGJldHdlZW4gKDEtMykuXG4iOwp9Cn0=
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