Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- typedef struct structure{
- int t;
- float tp;
- float tt;//declared values
- float tf;
- } values;
- void random_values (float *tp,float *tt,float *tf){
- *tp = rand() % (201)+500;
- *tt = rand() % (101)+100;//random variables
- *tf = rand() % (11)+10;
- }
- void print (values circular_values[21], int total_time){
- printf("t - tp - tt - tf\n");
- int offset;
- if (total_time+10<21) {
- offset=((total_time+10)*-1)+11;
- }
- else{
- offset=-10;
- }
- int i;
- for ( i =offset; i<11;i++){
- int array_location=(total_time+i-1) % 21;
- printf("%d - %.0f - %.0f - %.0f\n", offset, circular_values[array_location].tp, circular_values[array_location].tt, circular_values[array_location].tf);
- offset++;
- }
- }
- int main() {
- srand((time(0)));
- int t=0;
- float tf,tt;
- float tp=1000;
- values circular_values[21];
- int hascountdown_started=0;
- int countdown_value=0;
- while(countdown_value<10){
- float current_tp;
- current_tp=tp;
- random_values(&tp,&tt,&tf);
- values placeholder;
- placeholder.t=t;
- placeholder.tp=tp;
- placeholder.tf=tf;
- placeholder.tt=tt;
- circular_values[t % 21]=placeholder;
- t++;
- if (hascountdown_started == 1){
- countdown_value++;
- }
- if ((tp-current_tp)>=100){
- hascountdown_started=1;
- }
- }
- FILE*fout;
- fout=fopen("output.txt","r");
- print(fout,circular_values,t-10);
- fclose(fout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement