Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RAIN SIMULATION PROBLEM 3

Status
Not open for further replies.

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;}
----------------------------------
 
One error is, that in the procedure gjenero_rresht you changed the assignment operator with the logical equals operator,
you should have instead of
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.
 
Also you made some other errors:

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

You should use address-of here:

scanf("%d",&era);
scanf("%l",&k);
 
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
 
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

 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top