I was given the formula as follows:
but I'm not sure how to incorporate it into the program. I am also wondering if this formula would also allow me to calculate the values for distance when given a time not in the array. Say, I wanted to enter in the time "11.8", would the formula allow me to calculate the distance for that time?#include <stdio.h>
#include <stdlib.h>
#define size 8
double getDistance(int time[], double distance[], double test);
int main(void)
{
int time[size] = {0,3,5,8,10,12,15,18};
double distance[size] = {2, 5.2, 6, 10, 10.4, 13.4, 14.8, 18};
float test;
char choice;
do
{
printf("Please enter a time between 0 and 18: ");
scanf("%f", &test);
while(test < 0)
{
printf("The number you have entered is invalid, please enter another number. ");
scanf("%f", &test);
}
while(test > 18)
{
printf("The number you have entered is invalid, please enter another number. ");
scanf("%f", &test);
}
getDistance(time, distance, test);
printf("Do you want to enter another number? (Y/N) ");
while(getchar() != '\n') continue;
scanf("%c", &choice);
}while(choice != 'N');
system("pause");
return 0;
}
double getDistance(int time[], int distance[], int test)
{
}

New Topic/Question
Reply


MultiQuote



. f(x) would be the y's obviously.


|