hi, I am trying to write a code that prints the following bumbs when the function void Ascii::printBumps(int num, char symbol1, char symbol2)is called with (4,'%','#').
so far i have figured out how to print the triangles side by side by using
for(int i = width;i>=1;i--){
for(int j = 1;j<i;j++){
cout<<" ";
}
for(int k = width; k>=i; k--){
cout<<symbol<<" ";
}
cout<<endl;
}
for(int i = 1;i<=width-i;i++){
for(int j = 1;j<=i;j++){
cout<<" ";
}
for(int k = width-1 ; k>=i;k--){
cout<<symbol<<" ";
}
cout<<endl;
}
i cannot however figure out how to print the bumps and how to get the triangle size to increase each time.
#include <iostream>
void print_upper_triangle( int n, char c )
{
if( n > 1 ) print_upper_triangle( n-1, c ) ;
for( int i = 0 ; i < n ; ++i ) std::cout << c ;
std::cout << '\n' ;
}
void print_lower_triangle( int n, char c )
{
for( int i = 0 ; i < n ; ++i ) std::cout << c ;
std::cout << '\n' ;
if( n > 1 ) print_lower_triangle( n-1, c ) ;
}
void print_bumps( int n, char symbol1, char symbol2 )
{
if( n > 1 ) print_bumps( n-1, symbol1, symbol2 ) ;
print_upper_triangle( n, symbol1 ) ;
print_lower_triangle( n, symbol2 ) ;
}
int main()
{
print_bumps( 5, 'X', 'Y' ) ;
}
#include <iostream>
usingnamespace std;
void row( int n, char symbol )
{
while ( n-- ) cout << symbol << ' ';
cout << '\n';
}
void bumps( int number, char symbol1, char symbol2 )
{
for ( int n = 1; n <= number; n++ )
{
for ( int i = 1; i <= n; i++ ) row( i, symbol1 );
for ( int i = n; i >= 1; i-- ) row( i, symbol2 );
}
}
int main()
{
bumps( 4, '%', '#' );
}