Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question Details: C++ Write a program that reads in the size of the side of a sq

ID: 3616769 • Letter: Q

Question

Question Details: C++ Write a program that reads in the size of the side of a squarethen prints a hollow square of the size out of the asterisks andblanks. Your program should works for squqresof all side sizes between 1 and20. For example, if your program reads a size of 5, itshould print ***** *      * *      * *      *      *****      Question Details: C++ C++ Write a program that reads in the size of the side of a squarethen prints a hollow square of the size out of the asterisks andblanks. Your program should works for squqresof all side sizes between 1 and20. For example, if your program reads a size of 5, itshould print ***** *      * *      * *      *      *****     

Explanation / Answer

hope you will rate Life Saver...

#include<iostream>
using namespace std;
int main()
{
int v,j,stars=0;
while(true)
    {
cout<<"Enter size: ";
    cin>>stars;

if(stars>0&&stars<21) /* means if theuser data is greater than zero (&&=and) and less than 21,data is valid exit from loop, break statement will take you outfrom loop */
break;
    }
for(v=0;v<stars;v++)
cout<<"*";   //upper side isprinted.
cout<<endl;

for(v=0;v<stars-2;v++)  //upper and lower line notadded remaining side will print.
{
cout<<"*";   //first * of side is printed
for(j=0;j<stars-2;j++) //gap between left side andright side is printed.
      cout<<" ";  //onlyspace is printed.
cout<<"*"<<endl;  //right side of the squareis printed.
}

if(stars>1)   //if stars are greater than onethen bottom line should be print   
for(v=0;v<stars;v++)  //bottom line is printed..
cout<<"*";   //wait for userinput..
system("pause");  //Execute perfectly.
return 0;
}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote