Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. typedef struct structure{
  5.  
  6. int t;
  7. float tp;
  8. float tt;//declared values
  9. float tf;
  10. } values;
  11. void random_values (float *tp,float *tt,float *tf){
  12. *tp = rand() % (201)+500;
  13. *tt = rand() % (101)+100;//random variables
  14. *tf = rand() % (11)+10;
  15. }
  16. void print (values circular_values[21], int total_time){
  17.  
  18. printf("t - tp - tt - tf\n");
  19.  
  20. int offset;
  21. if (total_time+10<21) {
  22. offset=((total_time+10)*-1)+11;
  23. }
  24. else{
  25. offset=-10;
  26. }
  27.  
  28. int i;
  29. for ( i =offset; i<11;i++){
  30. int array_location=(total_time+i-1) % 21;
  31. printf("%d - %.0f - %.0f - %.0f\n", offset, circular_values[array_location].tp, circular_values[array_location].tt, circular_values[array_location].tf);
  32. offset++;
  33. }
  34. }
  35.  
  36. int main() {
  37.  
  38. srand((time(0)));
  39.  
  40. int t=0;
  41. float tf,tt;
  42. float tp=1000;
  43.  
  44. values circular_values[21];
  45. int hascountdown_started=0;
  46. int countdown_value=0;
  47.  
  48. while(countdown_value<10){
  49. float current_tp;
  50. current_tp=tp;
  51.  
  52. random_values(&tp,&tt,&tf);
  53.  
  54. values placeholder;
  55. placeholder.t=t;
  56. placeholder.tp=tp;
  57. placeholder.tf=tf;
  58. placeholder.tt=tt;
  59. circular_values[t % 21]=placeholder;
  60.  
  61. t++;
  62.  
  63. if (hascountdown_started == 1){
  64.  
  65. countdown_value++;
  66. }
  67. if ((tp-current_tp)>=100){
  68. hascountdown_started=1;
  69. }
  70.  
  71. }
  72.  
  73. FILE*fout;
  74. fout=fopen("output.txt","r");
  75. print(fout,circular_values,t-10);
  76. fclose(fout);
  77.  
  78. return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement