i need help building a simple C++ program?

  • Thread starter Thread starter michelle c
  • Start date Start date
M

michelle c

Guest
The problem I have is that I have to display the following:
**
****
******
********
**********
the instructions have to display the pattern above: (2 asterisks, 4, 6, 8, 10, and 12). I have the following but it is not working. please help

#include <iostream>

using namespace std;

int main()
{
//declare constants and variables
int x = 0;
int y = 0;

for (int x = 1; x <= 5; x = x + 1)
{
for (int y = 1; y != x; y = y + 1)
cout << "*";
}

return 0;
} //end of main function
 
First off, you are re-declaring 'int x' and 'int y'. Try this:

int x = 0, y = 0;

for (x; x <= 6; x++)
{
for (y = 0; y <= (x * 2); y++)
cout << "*";
}

I cannot guarantee that it will work. But I think it should.
 
Back
Top