P
paolo.arimado
Dear everyone,
Can someone please help me on my HW. I'm trying to write a program
that will display the following:
*
***
*****
*******
*********
*********
*******
*****
***
*
For this particular HW, I can only use for loops and is limited to
three for loops. I'm also limited to one cout="*" and one cout=" ".
However, I can use as many cout << endl; as I can.
I'm having a hard time writing a code for this one. I tried several
times, but I can't get it to work properly. I live in Japan and I take
an online C++ course. The instructor lives in the US so whenever I am
awake, he's asleep. Therefore, I cannot contact him directly when I
need help. I have to get this program up and running ASAP. I tried
searching everywhere for help, but there's none except for this group.
My textbook isn't much of a help either. I WILL GREATLY APPRECIATE THE
HELP I WILL GET!
Code:
#include <iostream>
using namespace std;
int main()
{
const int SIZE = 9;
const int SPACE = 10;
int i, j;
int k = SIZE / 2;
for (i = 1; i <= SPACE; i++) {
for (j = 0; j < (k - i) + 1; j++)
cout << " ";
for (j = 0; j < i; j++)
cout << "*";
cout << endl;
}
cin.ignore();cin.ignore();
return 0;
}
When I compile and run it, I get the following output:
*
**
***
****
*****
******
*******
********
*********
**********
It's kind of hard to see from here. Try to compile the code and test
it. You'll see it better.
Can someone please help me on my HW. I'm trying to write a program
that will display the following:
*
***
*****
*******
*********
*********
*******
*****
***
*
For this particular HW, I can only use for loops and is limited to
three for loops. I'm also limited to one cout="*" and one cout=" ".
However, I can use as many cout << endl; as I can.
I'm having a hard time writing a code for this one. I tried several
times, but I can't get it to work properly. I live in Japan and I take
an online C++ course. The instructor lives in the US so whenever I am
awake, he's asleep. Therefore, I cannot contact him directly when I
need help. I have to get this program up and running ASAP. I tried
searching everywhere for help, but there's none except for this group.
My textbook isn't much of a help either. I WILL GREATLY APPRECIATE THE
HELP I WILL GET!
Code:
#include <iostream>
using namespace std;
int main()
{
const int SIZE = 9;
const int SPACE = 10;
int i, j;
int k = SIZE / 2;
for (i = 1; i <= SPACE; i++) {
for (j = 0; j < (k - i) + 1; j++)
cout << " ";
for (j = 0; j < i; j++)
cout << "*";
cout << endl;
}
cin.ignore();cin.ignore();
return 0;
}
When I compile and run it, I get the following output:
*
**
***
****
*****
******
*******
********
*********
**********
It's kind of hard to see from here. Try to compile the code and test
it. You'll see it better.