You are to write a short program that will input a positive integer numbers in t
ID: 3630489 • Letter: Y
Question
You are to write a short program that will input a positive integer numbers in the range 1 - 10. If the input numbers are not in the correct range a message should be sent to the user. Error messages are sent until correct input is submitted. Correct input numbers are used to print a rectangle which has sides named length and width. The printed rectangle is made up of an input character. After the figure is printed you are to ask the user if another rectangle is to be printed. Note that the input to the request for another rectangle is insensitive to case.
Enter length and width values (!= 0) for a filled rectangle.
Enter the length of the rectangle (+1 to +10): -8
Input Error -----
Enter the length of the rectangle (+1 to +10): 8
Enter the width of the rectangle (+1 to +10): 0
Input Error -----
Enter the width of the rectangle (+1 to +10): 4
Enter the symbol to be used: X
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
Do you want another rectangle, Yes or No: yes
Enter the length of the rectangle (+1 to +10): 1
Enter the width of the rectangle (+1 to +10): 1
Enter the symbol to be used: A
A
Do you want another rectangle, Yes or No: no
Explanation / Answer
#include<iostream>
using namespace std;
void fillCharacter(int, int, char);
int main()
{
int number1,number2;
char ch;
cout << " Enter the length of the rectangle (+1 to +10): ";
cin >> number1;
if(number1 <= 0)
{
cout<<" ERROR";
cout<<" Enter correct value : ";
cin>>number1;
}
cout << " Enter the width of the rectangle (+1 to +10): ";
cin>>number2;
if(number2 <= 0)
{
cout<<" ERROR";
cout<<" Enter correct value : ";
cin>>number2;
}
cout<<" Enter a character : ";
cin >> ch;
fillCharacter(number1,number2,ch);
system("pause");
return 0;
}
void fillCharacter(int number1, int number2,char ch)
{
for (int i = 1; i <= number2; i++)
{
for (int j = 1; j <= number1; j++)
cout << ch;
cout << endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.