Program to display shapes?

So, I'm trying to write code for a program that outputs stars (*) and spaces to create shapes based on an integer the user inputs. I was given a template in class but I honestly have no idea how to begin using voids. If anyone could help in anyway I'd be so appreciative!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 
#include <string>
#include <iostream>
using namespace std

int main()
{
  int number;
  
  do
  {
      cout << "Enter a positive number: " << endl;
      cin >> number;
      if (number < 1)
      {
       cout << "Error, Please enter a positive number." << endl;   
      }
  }
       while (number > 1);
      
       displayRightTriangle(number);
       displaySquare(number);
       displayLeftTriangle(number)
       displayUpperRightTriangle(number);
       
       cin.ignore();
       cin.get();
       return 0;
}

void displaySpaceAndStars (int spaces, int stars)
{
    
}

void displaySquare (int n)
{
    
}

void displayLeftTriangle (int n)
{
    
}

void displayRightTriangle (int n)
{
    
}

void displayUpperRightTriangle (int n)
{
    
}
Last edited on
You have given the sizes (int n) for each shape, so you need to code in each function how to print the shape of a size of n.

Here an example of displaySquare():
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
voiid displaySquare(int n)
{
    // print the upper bar
    for (int i = 0;  i < n;  ++n)  { cout << '*'; }
    cout << '\n';

    // print side bars
    for( int i = 0; i < n-2; ++n)
    {
        cout << '*';

        // print some of spaces
        for( int k = 0; k < n - 2; ++k) { cout << ' '; }
       
        cout << "*\n";
    }
    
    // print the lower bar
    for( int i = 0;  i < n;  ++n) { cout << '*'; }

    cout << '\n';
}
Last edited on
Topic archived. No new replies allowed.