我的一项职能有问题。这是代码:
include <stdio.h>
include <math.h>
include <stdlib.h>
int inputAmount(int i);
void inputFahrs(double data[ ], int j);
double fahrToCels (double data[ ], int j);
void outputFahrs(double data [ ], int numFahrs);
void outputAverage(double data[ ], int numFahrs);
void outputHighLows(double data[ ], int numFahrs);
void outputGrads(double data[ ], int numFahrs);
int main (void)
{
int i, j, numFahrs;
double data[i], *ptr=&data[i];
i=inputAmount(i);
printf("%d\n\n", i);
inputFahrs(&data[i], i);
data[j]=fahrToCels(&data[i], j);
printf("%.1f", data[j]);
return 0;
}
int inputAmount(int i)
{
printf("Please enter the amount of vaues you would like to use.\n\n");
scanf("%d", &i);
while(i<1 || i>25)
{
printf("Value is out of range. Please enter another value.\n\n");
scanf("%d", &i);
}
return i;
}
void inputFahrs(double data[ ], int i)
{
int j;
printf("Please enter temperature values in the range of -175 to 175 degrees F.\n\n");
for(j=0;j<i;j++)
{
scanf("%f", &data[j]);
if (data[j]< -175 || data[j]>175)
{
printf("Temperature value is out of range. Please re-enter");
scanf("%f", &data[j]);
}
}
}
double fahrToCels (double data[ ], int j)
{
int i;
printf("TEST");
for(j=1;j<=i;j++)
{
data[i]=(((data[i])-32)*(5.0/9.0));
}
return data[i];
}
基本上我的代码中的问题是它if
完全跳过了该语句。我希望程序通过for
循环,如果用户输入的值超出范围,我希望if
语句开始。for
循环内的打印语句,但在if
语句之后工作正常,所以这肯定是有问题的。我还尝试了一个while
循环来代替if
.