HELP with problem please!!!

Aug 4, 2012 at 10:19am
I want to write a program the uses a while loop to get integers from a user. then using nested for loops, creates a square of the number using asterisks. when this said user enters zero then the program ends.

does anyone know how to go about doing this. an example of what the output should look like is this:

cout << "Enter an integer: ";
cin >> number;


Enter an integer: 5
*****
*   *
*   *
*   *
*****
Last edited on Aug 4, 2012 at 10:21am
Aug 4, 2012 at 10:57am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

using namespace std;

int main()
{
    int temp; // store your input

    cout << "Enter an integer : ";
    cin >> temp;

    for(int i = 0; i < temp; i++)
    {
        cout << "*" << endl;
    }


    return 0;
}


if you insert 5, it produces :
1
2
3
4
5
*
*
*
*
*


you can modify it,
Aug 4, 2012 at 3:18pm
here is a small hint to help you.
on the first and last line it are all temp times '*' but on the lines between in the first and the last character only are a '*' so that means that you have to type N-2 spaces between them.
Topic archived. No new replies allowed.