HariDimoshi
Programmer
- May 16, 2009
- 2
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;[COLOR=red]//the matrix matrica[25][80] is the dos window in 25x80 resolution[/color]
void main(void)
{
long k;[COLOR=red]//for the delay() function that rapresents the speed of rain[/color]
int era;[COLOR=red]//rapresents the wind direction variable[/color]
setcursor(_NOCURSOR);
printf("Ju lutemi fusni drejtimin e eres: 1 per majtas-djathtas ose 2 per anasjelltas\n");
scanf("%d",era);[COLOR=red]//scanning the wind direction variable 1 for left-right 2 for right-left[/color]
printf("\nJu lutemi fusni shpejtesine/shpeshtesine e shiut ne milisekonda:\n");
scanf("%l",k);[COLOR=red]// scanning rain speed in milliseconds for the delay function[/color]
gjenero_rresht();[COLOR=red]//calling the function that generates the first row of the matrix(display) randomly[/color]
display();[COLOR=red]//calling the function that displays the rain characters as * or space.[/color]
move_matrix();[COLOR=red]//calling the function that moves matrix rows from up to down simulating the raining[/color]
delay(k);[COLOR=red]//calling the function that generates the speed of raining[/color]
wind(era);[COLOR=red]//calling the function that generates the direction of wind[/color]
shuma_5_zona();[COLOR=red]//calling the function that splits the display in 5 sections (virtually) to sum the raindrops at the end of each zone[/color]
return 0;
}
void gjenero_rresht(void)
{
for(j=0;j<80;j++)
matrica[0][rand()%80]==1;[COLOR=red]//generates the first random row and gives certain elements the valu of one[/color]
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)[COLOR=red]//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.[/color]
matrica[i][j]==0;
}
{
if (matrica[i][j]==1)[COLOR=red]// it prints * for the cells that have the value of 1 and space for the cells that have the value of 0.[/color]
printf("*");
else printf(" ");
return 0;}
void move_matrix(void)
{
while(!kbhit())
{
for(i=1;i<24;i++) [COLOR=red]//moves the rows of the matrix up-down[/color]
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++)[COLOR=red]//for the value of the variable "era" 1,it moves cells from left to right[/color]
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++)[COLOR=red]// for the value of era=2 it moves the cells from right to left[/color]
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++)[COLOR=red]// 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[/color]
{
for(i=0;i<25;i++)
for(j=l*16;j<l*16+16;j++)
v[l]+=matrica[i][j];
}
return 0;}