Hi Guys. I'm writing a program to accept some values, store them in arrays, then pass these arrays back the to caller to be printed. But when I print, i get weird output. like...0.002.007. Can anyone please help me to identify the problem?
Code:
void listValues()
{
int i;
char carModelArray[MAX] = {0};
float sLengthArray[MAX] = {0};
float rSlopeArray[MAX]= {0};
float speedArray[MAX] = {0};
readValues(&carModelArray,&sLengthArray,&rSlopeArray,&speedArray);
for (i = 0; i < 2; i++)
{
printf("%.3f",speedArray[i]);
}
getch();
}
//Module that allows the user to enter the values
void readValues(char (*carModelArray)[MAX],float (*sLengthArray)[MAX],float (*rSlopeArray)[MAX],float (*speedArray)[MAX])
{
char carModel[25];
float speed,sLength = 0,rSlope;
int i = 0;
while(sLength != 999)
{
printf("\nPlease enter the model of the car ");
scanf("%s", &carModel[i]);
strcpy((*&carModelArray)[i],&carModel[i]);
printf("\nEnter the skid length made by the car");
scanf("%f", &sLength);
while(sLengthArray<=0 )
{
printf("\nThe skid length must be greater than zero <0>");
scanf("%f", &sLength);
}
(*sLengthArray)[i] = sLength;
printf("\nEnter the slope of the road ");
scanf("%f", &rSlope);
while(rSlope<-30|| rSlope >30)
{
printf("\nThe slope of the road must be greater than -30 and less than 30");
printf("\nEnter the slope of the road ");
scanf("%d", &rSlope);
}
(*rSlopeArray)[i] = rSlope;
i++;
speed = CalculateSpeed(sLength,rSlope);
(*speedArray)[i] = speed;
}
}
//Module to calculate the speed of the car
float CalculateSpeed(float skd_lgnth, float rd_slp)
{
float slopeRad,slopeTangent;
float speed,cosine,sine,answer;
slopeRad = rd_slp*(pi/180);
slopeTangent = (sin(slopeRad))/(cos(slopeRad));
answer = slopeTangent*(pi/180);
speed= sqrt(30*skd_lgnth*(answer+Brakefactor));
return speed;
getch();
}