The program my prof asked me to make, is to take the inputs of height(h) and width(w). width is within the range of 10 - 20. and height is 3 - 61.
i have to print amount random lines such that k = rand() % (w-1) + 2
my issue is that I have to compare whether the random number K is closer to "w" or zero. how can I make a comparison with a non-fixed integer?
What i have so far
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int main(void)
{
int h,w,k, x,y,z;
char l;
srand(time(NULL));
z=1;
x = rand();
while(z>0){
printf("Enter Width: ");
scanf("%d", &w);
printf("Enter height: ");
scanf("%d", &h);
if(w >= 10 && w <= 20){
if(h>=3 && h <= 61)
z= -1;
}
}
for(z=0;z < h; z++){
printf("%d: ",k);
k = (rand() % (w-1)) + 2;
if(~ ~ ~){ // <-- <-- <-- <-- <-- ****
for(y=0;y < k; y++){
printf(" ");
for(y=0;y < (k-1) ;y++){
printf("j");
}}}
else{
for(y=0;y < (k-1) ;y++){
printf("j");
}}
printf("\n");
}
return 0;
}
In my if statement. I want to compare if K is closer to my value W than 0. it will decide if I print K amount of zero's first or just print my characters.
->Edits have been made. still working on this. I will post an answer when I am done. if I figure it out.