#include<math.h>
#include<stdio.h>
#define arrayLength 25

typedef struct{
    double startTime; double endTime;
    double Time[arrayLength];
    double Altitude[arrayLength];
    double Velocity[arrayLength];
}Values;

void getInfo(Values*);
void calculate(Values*);

void main(){
    Values balloon; Values* balloonPTR = &balloon; int counter;
    getInfo(&*balloonPTR);
    calculate(&*balloonPTR);
    printf("\n\tTime(s)  \tAltitude(m)\tVelocity(m/s)\n");
    printf("\t----------------------------------------------\n");
    for(counter = 0; counter < arrayLength; counter = counter +1){
        printf("\t%2.2lf\t\t%5.2lf \t%5.2lf\n",
        balloon.Time[counter],balloon.Altitude[counter],balloon.Velocity[counter]);
    }
}

void getInfo(Values* PTR){
    printf("Please insert the starting and ending time 0 - 48 (s): ");
    scanf("%lf%lf",&PTR->startTime,&PTR->endTime);
    if(PTR->startTime < 0 || PTR->startTime > 48){
        do{
            printf("The start time must be between 0 and 48 seconds ");
            printf("\nPlease insert a valid start time: ");
            scanf("%lf",&PTR->startTime);
        }while(PTR->startTime < 0 || PTR->startTime > 48);
    }
    if(PTR->endTime < 0 || PTR->endTime > 48){
        do{
            printf("The end time must be between 0 and 48 seconds");
            printf("\nPlease insert a valid end time: ");
            scanf("%lf",&PTR->endTime);
        }while(PTR->endTime < 0 || PTR->endTime > 48);
    }
}

void calculate(Values* PTR){
    double increment = (PTR->endTime - PTR->startTime)/24;
    double count = PTR->startTime; int x = 0;
    for(x = 0; x < arrayLength; x = x+1){
        PTR->Time[x] = count;
        PTR->Altitude[x] = -0.12*pow(count,4)+12*pow(count,3)-380*pow(count,2)+(4100*count)+220;
        PTR->Velocity[x] = -0.48*pow(count,3)+36*pow(count,2)-(760*count)+4100;
        count = count + increment;
    }
}
