×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# RAIN SIMULATION PROBLEM3

## RAIN SIMULATION PROBLEM

(OP)
Hi!I have to do a rain simulation program (without graphics).I thought about it and wrote down my ideas,wrote the program but I don't know why it doesn't work!The program has to simulate rain falling and count the drops of rain that fall down,other parameters are the wind direction and rain speed.Below it's my "program" commented.Please help me because I'm new to C language(one month studying it).

-------------------------------------------------------

#### CODE

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

int matrica[25][80],i,j;//the matrix matrica[25][80] is the dos window in 25x80 resolution
void main(void)
{
long k;//for the delay() function that rapresents the speed of rain
int era;//rapresents the wind direction variable
setcursor(_NOCURSOR);

printf("Ju lutemi fusni drejtimin e eres: 1 per majtas-djathtas ose 2 per anasjelltas\n");
scanf("%d",era);//scanning the wind direction variable 1 for left-right 2 for right-left

printf("\nJu lutemi fusni shpejtesine/shpeshtesine e shiut ne milisekonda:\n");
scanf("%l",k);// scanning rain speed in milliseconds for the delay function

gjenero_rresht();//calling the function that generates the first row of the matrix(display) randomly
display();//calling the function that displays the rain characters as * or space.
move_matrix();//calling the function that moves matrix rows from up to down simulating the raining
delay(k);//calling the function that generates the speed of raining
wind(era);//calling the function that generates the direction of wind
shuma_5_zona();//calling the function that splits the display in 5 sections (virtually) to sum the raindrops at the end of each zone
return 0;
}

void gjenero_rresht(void)
{
for(j=0;j<80;j++)
matrica[0][rand()%80]==1;//generates the first random row and gives certain elements the valu of one
return 0;}

void display(void)
{
gotoxy(0,0);
for(i=0;i<25;i++)
for(j=0;j<80;j++)
{
if (matrica[i][j]!==1)//for the cells tht doesn't have the value of one it gives the value of zero.This serves to sum rain drops  in each zone from 5.
matrica[i][j]==0;
}
{
if (matrica[i][j]==1)// it prints * for the cells that have the value of 1 and space for the cells that have the value of 0.
printf("*");
else printf(" ");
return 0;}

void move_matrix(void)
{
while(!kbhit())
{
for(i=1;i<24;i++)   //moves the rows of the matrix up-down
for(j=0;j<80;j++)
{
matrica[i][j]=matrica[i-1][j];
}
for(j=0;j<80;j++)
matrica[0][j]=matrica[25][j];
}
return 0;}

void delay(long k)
{
delay(k);
return 0;
}

void wind(int era)
{
if(era=1)
{
for(i=1;i<24;i++)//for the value of the variable "era" 1,it moves cells from left to right
for(j=0;j<80;j++)
{
matrica[i][j]=matrica[i][j-1];
}
for(i=0;i<25;i++)
matrica[i][0]=matrica[i][80];
}

else if(era=2)
{
for(i=0;i<25;i++)// for the value of era=2 it moves the cells from right to left
for(j=0;j<80;j++)
{
matrica[i][j]=matrica[i][j+1];
}
for(i=0;i<25;i++)
matrica[i][0]=matrica[i][80];
}
}
return 0;
}

void shuma_5_zona(void)
{
int v[80],l;

for(l=0;l<5;l++)// and finally it splits virtually and sums each of 5 zones putting it in a vector.the program isn't finished because these data should be putted into a *.txt file to be opened later for the statistics
{
for(i=0;i<25;i++)
for(j=l*16;j<l*16+16;j++)
v[l]+=matrica[i][j];
}
return 0;}
----------------------------------

### RE: RAIN SIMULATION PROBLEM

One error is, that in the procedure gjenero_rresht you changed the assignment operator with the logical equals operator,
matrica[0][rand()%80]==1
this
matrica[0][rand()%80]=1

If you are not familiar with the given programming language do not write the whole program at once. First you should write a working skeleton only and then in further steps add the additional functionality. And with doing every change you should recompile the program. If an error occurs you should first correct it and then go to the further step.
If you search for errors your compiler helps you with the error messages.

### RE: RAIN SIMULATION PROBLEM

Also you made some other errors:

long k;
int era;
scanf("%d",era);
scanf("%l",k);

scanf("%d",&era);
scanf("%l",&k);

### RE: RAIN SIMULATION PROBLEM

Another good idea it's to tell why it's not working, I mean, what results are you getting different from the expected ones

Cheers,
Dian

### RE: RAIN SIMULATION PROBLEM

(OP)
Thankyou for the tips, but still doesnt work.To be more specific as Diancecht said, below are listed all the errors that my compiler (dev C++)displays:

4: error: syntax error before '/' token

71: invalid suffix "x80" on integer constant
12: error: syntax error before string constant
12: error: conflicting types for 'printf'
12: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
12: error: conflicting types for 'printf'
12: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
12: warning: data definition has no type or storage class
13: error: syntax error before string constant
13: error: conflicting types for 'scanf'
13: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
13: error: conflicting types for 'scanf'
13: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
13: warning: data definition has no type or storage class
16: error: syntax error before string constant
16: warning: data definition has no type or storage class
In function gjenero_rresht':
33: error: syntax error before '/' token
In function display':
45: error: syntax error before '=' token
45: error: missing terminating ' character
49: error: syntax error before '/' token

52: warning: return' with a value, in function returning void
In function move_matrix':
60: error: syntax error before '/' token
61: error: syntax error before ')' token
In function display':
68: warning: return' with a value, in function returning void
In function delay':
75: warning: return' with a value, in function returning void
In function wind':
85: error: syntax error before '/' token
86: error: syntax error before ')' token
At top level:
95: error: syntax error before "else"
In function shuma_5_zona':
116: error: syntax error before '/' token
116: error: missing terminating ' character
118: error: syntax error before ')' token
119: error: syntax error before ')' token

Execution terminated

### RE: RAIN SIMULATION PROBLEM

One thing that you might try is using standard C comments /* comment here */ rather than the // from C++.  That should take care of several of the errors.

Lee

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!