Randomly generated square

I'm really confused about how to do this problem, mathematically, and I would appreciate some help. The instructions are as follows:

"Similar to halfFilledRectangle with a frame, but inside the proportion of fill_char to space is ratio. Ratio is a float from 0 (no fill), to 1 (full fill). Use rand() to randomly fill the rectangle and be able to handle any value between 0 and 1 inclusive. Give a warning and exit if the given ratio is <0 or > 1. Assume srand will be called in main."

And the prototype and output for this function are:
 
void partialFilledRectangle(int width, int height, char fill_char, float ratio);


Which shape should I draw?7
What is Fill Character? &
Width?10
Height?8
Ratio?0.1
&&&&&&&&&&
&        &
&  &     &
&        &
&    &   &
&        &
&        &
&&&&&&&&&&


Currently I have this code, which creates a square frame that is half filled. I'm very confused about how to modify it; could I please have some help?
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
#include <iostream>

using namespace std;

int main(){

  int width;
  int height;
  int shape;
  
  cout << "Welcome to Picture Maker!\nWhich shape should I draw?: ";
  
  cin >> shape;
  if(shape == 4){
    cout << "Width?: ";
    cin >> width;
    cout << "Height?: ";
    cin >> height;
    for(int a = 0; a < height; a++){
      for(int b = 0; b < width; b++){
        if(a == 0 || a == height - 1 || b == 0 || b == width - 1){
          cout << "*";
        }else{
          if(( a + b ) % 2 == 0){
            cout << " ";
        }else{
            cout << "*";
        }
      }
    }
    cout << endl;
  }
}
}
Once you have identified the cells to shade, for each cell, you need to generate a random number which is used to determine if you shade that cell or not.

If there's 1% chance of filling it, you could generate a number in the range 0-99 and only fill it when you get 0 for example.
Topic archived. No new replies allowed.