Question

In: Computer Science

Can't figure out what I am doing wrong. Please let me know. Sample output: Please enter...

Can't figure out what I am doing wrong.

Please let me know.

Sample output:

Please enter the name of the weather data file: temperatures.txt

Tell me about your crew’s preferred temperature for sailing:

What is the coldest temperature they can sail in? 60

What is the hottest temperature they can sail in? 80

Month 1: 93.3 percent of days in range.

Month 2: 20.0 percent of days in range.

Month 3: 58.1 percent of days in range.

Month 4: 100.0 percent of days in range.

Month 5: 100.0 percent of days in range.

Month 6: 50.0 percent of days in range.

Month 7: 64.5 percent of days in range.

Month 8: 9.7 percent of days in range.

Month 9: 60.0 percent of days in range.

Month 10: 100.0 percent of days in range.

Month 11: 93.3 percent of days in range.

Month 12: 83.9 percent of days in range.

You should leave for the Caribbean in month 4!

Numbers for the file:

15

63.4

66.1

67.2

58.5

61.9

68.2

65.3

70.0

72.9

71.8

70.1

70.3

69.5

66.1

70.8

5

56.5

57.1

55.0

58.0

66.2

31

54.0

53.2

46.6

47.4

56.7

62.6

53.7

57.5

60.7

65.7

66.0

67.8

62.3

58.3

55.6

60.2

62.8

70.5

72.9

71.0

61.8

61.6

71.2

73.0

68.6

56.6

51.2

56.0

59.7

62.1

69.2

20

72.3

72.8

71.5

71.3

69.4

64.6

68.7

70.6

72.5

72.2

78.0

78.6

77.4

75.4

69.3

77.3

74.2

75.7

79.9

72.2

30

72.8

70.9

72.7

73.0

71.8

69.6

61.3

71.7

73.4

76.6

77.5

77.3

76.1

71.5

72.4

73.7

75.0

77.8

77.1

77.3

73.5

74.7

78.2

78.8

78.2

73.6

69.3

76.9

76.0

78.5

30

79.2

80.3

78.9

78.7

75.8

75.6

78.4

80.0

78.1

80.7

79.4

79.9

81.9

82.2

82.0

81.0

80.8

81.3

82.4

80.7

78.0

82.3

77.7

81.6

81.7

80.7

79.0

80.4

79.1

78.2

31

76.4

76.2

78.1

78.9

80.4

81.8

82.4

82.4

82.1

80.8

80.3

78.7

78.2

77.5

77.5

78.1

79.3

78.6

77.3

77.6

80.1

79.3

78.6

79.7

79.9

81.6

78.0

79.6

79.9

83.0

82.2

31

81.1

81.9

81.6

80.0

82.7

81.2

83.6

83.0

82.0

82.3

83.6

83.1

83.6

82.5

81.7

82.2

82.8

82.3

81.8

83.0

83.1

80.4

81.8

80.2

79.0

79.9

80.8

80.3

81.6

82.6

81.2

30

79.9

78.8

79.6

80.9

81.3

80.6

77.8

80.9

81.7

81.8

81.8

79.7

79.7

82.5

81.7

80.2

80.5

78.1

79.3

78.7

78.7

79.1

77.1

77.5

76.7

80.6

76.0

76.8

78.0

77.8

31

79.1

78.5

78.7

79.5

79.5

79.2

77.1

78.9

75.5

74.6

74.9

75.8

76.1

76.0

73.2

76.9

77.4

78.4

79.0

76.5

79.8

79.6

76.8

67.8

68.3

67.5

67.1

68.5

71.8

74.1

75.3

30

77.1

71.3

67.2

68.7

73.2

74.2

70.1

70.8

70.5

72.0

72.1

71.1

64.8

62.7

68.1

70.7

75.1

75.9

73.8

71.7

73.1

73.9

73.7

67.9

67.1

72.7

69.7

50.6

59.5

64.5

31

66.1

66.1

65.8

69.6

71.4

74.1

73.2

72.8

73.1

71.8

72.0

65.9

60.0

69.7

70.9

59.3

57.1

58.4

59.1

65.8

72.7

75.0

74.7

68.6

58.8

64.6

65.2

70.1

73.4

65.2

62.3

#include <stdio.h>
#include <stdlib.h>

#define MONTHS 12
#define DAYS 31

// Main Function
int main(void){

FILE* f;

// Declared Variables
int month, day, low, high, sailmonth[12], temperature, besttime, i, j;
float array[MONTHS][DAYS],num, sum, average;
char data[30];

printf("Please enter the name of the weather data file:/n");
scanf("%s", data);

printf("Tell me about your crew’s preferred temperature for sailing:/n");

printf("What is the coldest temperature they can sail in?/n");
scanf("%d", &low);

printf("What is the hottest temperature they can sail in?/n");
scanf("%d", &high);

if((f = fopen(data, "r")) == NULL)
exit(1);
for(months = 0; months < 12; months++){
for (day = 0; day ,31; day++){
if(fscanf(f, "%f", &array[months][days]) != 1)
exit(1);
fclose(f);
}
}
for (months = 0; months < 12; months++)
{
sum = 0
num = array[months][0];
for (days = 1; days <31; days++)
{
if (array[months][days] >= low && array[months][days] <= high)

{


printf("%f", array[months][months]);
sum = sum + array[months][months];
}
}
}

average = sum/num:
printf("Month %d: %f percent of days in range.", average, month);
sailmonth[month] = int (average);

for (i = 0; i < 12; i++)
{
besttime = 0;
for (j = i + 1; j < 12; j++)
{
if (sailmonth[i] > sailmonth[j])
{
temperature = sailmonth[i];
sailmonth[i] = sailmonth[j];
sailmonth[j] = temperature;
besttime = i;
}
}
}

printf("You should leave for the Carribean in month %d.", besttime);
return 0;
}

Solutions

Expert Solution

Importing data from a text file and then working on it , definitely a nice work and code has been nicely written too ....
But what you missed was the few typing errors , and to sort out that , Indenting the code is the best approach

1. At line no. 20 :-> In the for loop it was used "day" while "days" was initialized because whatever indexing variable one is using the array only that variabe should be used . Also it was written "day=30;day,31;day++" but it should be "days=0;days<31;days++".

2. At line 28 :-> A semicolon was missed . "sum = 0" typo error as "sum = 0;" was required

3. At line 40. :-> Same mistake of typo error . "average = sum/num:"

4. At one place the closing bracket was placed 3 lines earlier resulting in "printf("Month %d: %f percent of days in range.", average, month);" printing only once , while it was intended to print in the loop
Hence, At line 39 :-> The closing braacket was placed "}" while this bracket should have come after line 42.

Code For refrencing line numbers : (I have indented the code as it always helps me out)

1. #include <stdio.h>
2. #include <stdlib.h>
  
3. #define MONTHS 12
4. #define DAYS 31
  
// Main Function
5. int main(void){
  
6. FILE* f;
  
// Declared Variables
7. int month, day, low, high, sailmonth[12], temperature, besttime, i, j;
8. float array[MONTHS][DAYS],num, sum, average;
9. char data[30];
  
10. printf("Please enter the name of the weather data file:/n");
11. scanf("%s", data);
  
12. printf("Tell me about your crew’s preferred temperature for sailing:/n");
  
13. printf("What is the coldest temperature they can sail in?/n");
14. scanf("%d", &low);
  
15. printf("What is the hottest temperature they can sail in?/n");
16. scanf("%d", &high);
  
17. if((f = fopen(data, "r")) == NULL)
18. exit(1);

19. for(months = 0; months < 12; months++){
20. for (day = 0; day ,31; day++){ ******************
21. if(fscanf(f, "%f", &array[months][days]) != 1) ********************
22. exit(1);
23. fclose(f);
24. }
25. }

26. for (months = 0; months < 12; months++)
27. {
28. sum = 0 *******************
29. num = array[months][0];
30. for (days = 1; days <31; days++)
31. {
32. if (array[months][days] >= low && array[months][days] <= high)
33.
34. {
35. printf("%f", array[months][months]);
36. sum = sum + array[months][months];
37. }
38. }
39. } ****************
  
40. average = sum/num: ***************
41. printf("Month %d: %f percent of days in range.", average, month);
42. sailmonth[month] = int (average);
  
****************
  
43. for (i = 0; i < 12; i++)
44. {
45. besttime = 0;
46. for (j = i + 1; j < 12; j++)
47. {
48. if (sailmonth[i] > sailmonth[j])
49. {
50. temperature = sailmonth[i];
51. sailmonth[i] = sailmonth[j];
52. sailmonth[j] = temperature;
53. besttime = i;
54. }
55. }
56. }
  
57. printf("You should leave for the Carribean in month %d.", besttime);
58. return 0;
59. }

Hope , It helps you out. If still stuck do comment please


Related Solutions

Okay, can someone please tell me what I am doing wrong?? I will show the code...
Okay, can someone please tell me what I am doing wrong?? I will show the code I submitted for the assignment. However, according to my instructor I did it incorrectly but I am not understanding why. I will show the instructor's comment after providing my original code for the assignment. Thank you in advance. * * * * * HourlyTest Class * * * * * import java.util.Scanner; public class HourlyTest {    public static void main(String[] args)     {        ...
Please let me know what the formulas are to calculate the following: I am seeing different...
Please let me know what the formulas are to calculate the following: I am seeing different answers and I don't know which is correct. E 15–26 Lease concepts; finance/sales-type leases; guaranteed and unguaranteed residual value Each of the four independent situations below describes a sales-type lease in which annual lease payments of $100,000 are payable at the beginning of each year. Each is a finance lease for the lessee. Determine the following amounts at the beginning of the lease: A....
In java, I keep getting the error below and I can't figure out what i'm doing...
In java, I keep getting the error below and I can't figure out what i'm doing wrong. Any help would be appreciated. 207: error: not a statement allocationMatrix[i][j];
I am supposed to map out the following and can't figure out how to do it!...
I am supposed to map out the following and can't figure out how to do it! Can somebody help? The experiment has to do with determining the simplest formula of potassium chlorate and to determine the original amount of potassium chlorate in a potassium chlorate-potassium chloride mixture by measuring the oxygen lost from decomposition. The chemical reaction is 2KClO3(s) ------> 2KCL(s) + 3 O2(g) I am supposed to map out 1. Mass of oxygen lost in the first part 2....
Hi, I can't figure out this question in excel, can someone please show me the excel...
Hi, I can't figure out this question in excel, can someone please show me the excel formulas to input in order to solve for part A and B please!!!! The following table contains closing monthly stock prices for Oracle Corporation (ORCL), Microsoft Corporation (MSFT), and NVidia (NVDA) for the first half of 2017. Ticker 6/30/2017 5/31/2017 4/30/2017 3/31/2017 2/28/2017 1/31/2017 ORCL 50.14 45.39 44.96 44.61 42.59 40.11 MSFT 68.93 69.84 68.46 65.86 63.98 64.65 NVDA 144.56 144.35 104.3 108.93 101.48...
I am getting an error at linen 57 and can't figure out how to fix it....
I am getting an error at linen 57 and can't figure out how to fix it. // Java program to read a CSV file and display the min, max, and average of numbers in it. import java.io.File; import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Scanner; public class Main {     // method to determine and return the minimum number from the array     public static int minimum(int numbers[])     {         int minIdx = 0;         for(int i=1;i<numbers.length;i++)         {             if((minIdx...
I just need 3 and 5. I am not sure what I am doing wrong. I...
I just need 3 and 5. I am not sure what I am doing wrong. I get different numbers every time. Superior Markets, Inc., operates three stores in a large metropolitan area. A segmented absorption costing income statement for the company for the last quarter is given below: Superior Markets, Inc. Income Statement For the Quarter Ended September 30 Total North Store South Store East Store Sales $ 4,800,000 $ 960,000 $ 1,920,000 $ 1,920,000 Cost of goods sold 2,640,000...
What am i doing wrong. I want for the program to run through then when it...
What am i doing wrong. I want for the program to run through then when it gets to "do you want to play again?enter yes or no" if they choose yes I want it to run again if they choose no then end. def play(): print("Welcome to the Game of Life!") print("A. Banker") print("B. Carpenter") print("C. Farmer") user_input = input("What is your occupation? ").upper() if user_input == "A": money = 100 elif user_input == "B": money = 70 elif user_input...
I am so desperate to know how to figure out if the industry is increasing, decreasing...
I am so desperate to know how to figure out if the industry is increasing, decreasing or constant cost industry by using given supply function, for example, S(p)= 200p - 3000. Please explain in detail Thanks
This is a question from Intro to Bayesian Statistics but I can't figure out what is...
This is a question from Intro to Bayesian Statistics but I can't figure out what is expected here. Derive the posterior distribution of obtaining heads in coin flips. The prior has p(θ = .25) = .25, p(θ = .50) = .50, and p(θ = .75) = .25. The data consist of a specific sequence of flips with 3 heads and 9 tails, so p(Data|θ) = θ^3 (1 − θ) ^9.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT