0

Write a program that reads 2 integers and draws a rectangle of corresponding dimensions.

modify the program such that in all casses the rectangle is always in horizontal position. meaning when the integers are switched the rectangle remains the same.

11th Aug 2020, 5:34 PM
Muhammad Hussein
Muhammad Hussein - avatar
12 Antworten
+ 3
All you would have to do to make sure the rectangle is always drawn horizontally is to add a simple if-statement to check if 'x', which denotes the height, is bigger than 'y', which is the length of the rectangle (tip: try to use clearer variable names), and if that is true, you simply swap their values. This ensures the length is always at least as great as the height (or bigger if we don't take a square into account), and the rectangle will be drawn accordingly.
11th Aug 2020, 5:54 PM
Shadow
Shadow - avatar
+ 11
share ur attempt first
11th Aug 2020, 5:36 PM
ÃKR
ÃKR - avatar
+ 3
please guys anyone to solve this for me
11th Aug 2020, 5:35 PM
Muhammad Hussein
Muhammad Hussein - avatar
+ 2
Its your code: https://code.sololearn.com/cA062nf98e4i/?ref=app now what you want?
11th Aug 2020, 5:51 PM
The future is now thanks to science
The future is now thanks to science - avatar
+ 2
Muhammad Hussein If x> y just replace the numbers.
11th Aug 2020, 5:56 PM
The future is now thanks to science
The future is now thanks to science - avatar
+ 1
Better if u try it and if error comes we can help👍
11th Aug 2020, 5:36 PM
Prasad Bankar
Prasad Bankar - avatar
+ 1
include <iostream> using namespace std; int main() { int x,y,i,j; cout<<"Enter two integers: "<<endl; cin>>x>>y; for(i=1; i<=x; i++) { for(j=1; j<=y; j++) { cout<<"*"; } cout<<endl; } return 0; }
11th Aug 2020, 5:39 PM
Muhammad Hussein
Muhammad Hussein - avatar
+ 1
okay thats my attempt.. i can print the rectangle but the modification part is where when you switch the inputs the rectangle is always in horizontal position i cant figure out
11th Aug 2020, 5:40 PM
Muhammad Hussein
Muhammad Hussein - avatar
+ 1
the program will print a rectangle like this.. lets you enter 2 and 4 **** **** then when you switch 4 and 2 it print ** ** ** ** Now on the part of modification, you modify the code to print just same position even when you switch the numbers.. i. e 2 & 4 **** **** 4 & 2 **** **** it should remain the same. //i dont know how to do this part //maybe we can use if function
11th Aug 2020, 5:54 PM
Muhammad Hussein
Muhammad Hussein - avatar
+ 1
do we have else in the if statement or we dont have
11th Aug 2020, 5:57 PM
Muhammad Hussein
Muhammad Hussein - avatar
0
Why it won't happen ? It should be Muhammad Hussein .What do you want?
11th Aug 2020, 5:50 PM
The future is now thanks to science
The future is now thanks to science - avatar
0
Here's my attempt to your challenge. Written in python https://code.sololearn.com/c1pkOB6qYyk1/?ref=app
13th Aug 2020, 2:25 PM
Jonas Anthony Ebora
Jonas Anthony Ebora - avatar