- Apr 1, 2001
- 1,427
- 0
- 0
Here is my code. When user inputs number of lines and their character, a pattern is displayed. However, my pattern has 1 extra line than the user inputs. I know it has to do with my loop parameters. Can anyone shed some light? Thanks in advance.
int main( )
{
int x;
char z;
cout << "Please enter number of lines" << endl;
cin >> x;
cout << "Please enter your character of choice" << endl;
cin >> z;
for (x = 1; x <= 20; x = x + 1)
{
for (int y = 1; y!=x ; y = y + 1)
cout << z;
cout << endl;
}
return 0;
}
int main( )
{
int x;
char z;
cout << "Please enter number of lines" << endl;
cin >> x;
cout << "Please enter your character of choice" << endl;
cin >> z;
for (x = 1; x <= 20; x = x + 1)
{
for (int y = 1; y!=x ; y = y + 1)
cout << z;
cout << endl;
}
return 0;
}