Guest User

Untitled

a guest
Jan 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. /* Matt Cain
  2. COP 3223
  3. Dr. Laviola
  4. Assignment #3 part 1 */
  5.  
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. FILE *file;
  9.  
  10. int main(void) {
  11.  
  12. float day_total = 0; //Entering variables
  13. float month_total = 0;
  14. int day_counter = 0;
  15. int month_counter = 0;
  16. int month_check, day_check;
  17. char filename[20];
  18.  
  19. printf("What is the month and day of your wedding?\n"); //Prompting user
  20. scanf("%d",&month_check);
  21. scanf("%d",&day_check);
  22.  
  23. printf("What file stores your city's temperature data?\n");
  24. scanf("%s",filename);
  25.  
  26. file = fopen(filename, "r"); //Opening file to read
  27.  
  28. while(1){ //Scanning the file for the below values
  29. int month, day, year;
  30. float temp;
  31.  
  32. fscanf(file,"%d",&month);
  33. fscanf(file,"%d",&day);
  34. fscanf(file,"%d",&year);
  35. fscanf(file,"%f",&temp);
  36.  
  37. if(month == -1) //Breaks out of loop if it finds a -1 (Placed at the bottom of the weather file to end)
  38. break;
  39.  
  40. if(day == day_check){
  41. day_counter++;
  42. day_total += temp;
  43. }
  44.  
  45. if(month == month_check){
  46. month_counter++;
  47. month_total += temp;
  48. }
  49. }
  50.  
  51. float day_average = day_total/day_counter;
  52. float month_average = month_total/month_counter;
  53.  
  54. printf("The average temperature on your wedding day is %.2f\n", day_average);
  55. printf("The average temperature on your wedding month is %.2f\n", month_average);
  56.  
  57. if ((day_average>=60 && day_average<=75) && (month_average>=60 && month_average<=75)) { //[60,75] Range
  58. printf("The weather looks good for an outdoor wedding!\n");
  59. }
  60. else
  61. printf("It's probably best to move the wedding indoors, sorry!\n");
  62.  
  63. fclose(file);
  64.  
  65.  
  66. system("PAUSE");
  67. return 0;
  68. }
Add Comment
Please, Sign In to add comment