// Includes
#include "stdafx.h"
#include <iostream>
#include <conio.h>
usingnamespace std;
// Main Function
int main()
{
int a;
int b;
int length;
int width;
cout << "This program will display a rectangle using the x character.\n\n";
cout << "Enter 1st number between 2 and 10: ";
cin >> a;
cout << "Enter 2nd number between 2 and 10: ";
cin >> b;
while ( a < 2 || a > 10 || b < 2 || b > 10)
{
cout << "Your numbers must be between 2 and 10: ";
cin >> a;
cin >> b;
}
if ( a > b )
{
length = a;
width = b;
}
elseif ( a < b )
{
length = b;
width = a;
}
else
{
width = length = a;
}
cout << "\n\nThe length of this rectangle is " << length << " and the width of this rectangle is " << width << "\n\n" << endl;
for (a = 1; a <= width; ++a)
{
for ( b = 1; b <= length; ++b)
{
cout << "X" << endl;
}
}
_getch();
return 0;
}
sorry for all these questions, this should be my last one tonight, my program i suppose to take a and b and make them length and width, well i got that, but then its suppose to display a rectangle using the character X.
Example: if the user entered 2 and 5 the length would be 5 and the width would be 2, then it would display this rectangle
XXXXX
XXXXX
my problem is i cant get it to display a rectangle, its only display something like this
// Includes
#include "stdafx.h"
#include <iostream>
#include <conio.h>
usingnamespace std;
// Main Function
int main()
{
int a;
int b;
int length;
int width;
cout << "This program will display a rectangle using the x character.\n\n";
cout << "Enter 1st number between 2 and 10: ";
cin >> a;
cout << "Enter 2nd number between 2 and 10: ";
cin >> b;
while ( a < 2 || a > 10 || b < 2 || b > 10)
{
cout << "Your numbers must be between 2 and 10: ";
cin >> a;
cin >> b;
}
if ( a > b )
{
length = a;
width = b;
}
elseif ( a < b )
{
length = b;
width = a;
}
else
{
width = length = a;
}
cout << "\n\nThe length of this rectangle is " << length << " and the width of this rectangle is " << width << "\n\n" << endl;
for (a = 1; a <= length; a++)
{
for ( b = 1; b <= width; b++)
{
cout << "X" << endl;
}
cout << endl;
}
_getch();
return 0;
}
Heres my new code, apparently i missed something now it displays: