MUST BE IN C Write a program that asks the user to enter an

(MUST BE IN C++)

Write a program that asks the user to enter an integer between 1 and 15. If the number entered is outside that range, your program should print out an error message and re-prompt for another number. (This is an opportunity to write an input validation loop.) Once the user enters a number in the correct range, your program will print out four patterns of asterisks that look like the following. Note that the number provided by the user is equal to the height of the pattern.

The ouput should like the image posted below for the two types of triangle. One pattern is for the right triangle and the other is for the isosceles triangle.

https://postimg.org/image/ycj5d786r/

Solution

#include<iostream.h>
#include<conio.h>

void main()
{
   clrscr();
   int n = 0,i,j,k;
   while(n<=1 || n>15) {
       cout<<\"Enter n: \";
       cin>>n;
   }
  
   for(i = n;i>0;i--) {
       for(j=1;j<=i; j++)
           cout<<\"*\";
       cout<<endl;
   }

   cout<<endl;
  
   for(i=n;i>0;i--){
       for(j=1;j<=n-i;j++)
           cout<<\" \";
      
       for(j=1;j<=i;j++)
           cout<<\"*\";
       cout<<endl;
   }
  
   cout<<endl;
  
   for(i=1;i<=n;i++){
       for(j=i;j<n;j++)
           cout<<\" \";

       for(j=1;j<=i*2-1;j++)
           cout<<\"*\";

       for(j=i;j<n;j++)
           cout<<\" \";
      
       cout<<endl;
   }

   cout<<endl;
  
   for(i=1;i<=n-1;i++){
       for(j=i;j<n;j++)
           cout<<\" \";

       for(j=1;j<=i*2-1;j++)
           if(j == 1 || j == i*2-1)
               cout<<\"*\";
           else cout<<\" \";
          
       for(j=i;j<n;j++)
           cout<<\" \";
      
       cout<<endl;
   }
   for(i=1;i<=2*n-1;i++) cout<<\"*\";
  
   getch();
  
}

(MUST BE IN C++) Write a program that asks the user to enter an integer between 1 and 15. If the number entered is outside that range, your program should print
(MUST BE IN C++) Write a program that asks the user to enter an integer between 1 and 15. If the number entered is outside that range, your program should print

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site