67.0k views
1 vote
Need assistance in C# code, using Visual Studio 2017. Can someone please explain why available coding solutions to the Weather Data problem below, do not work?

Weather Data (Starting Out With Visual C#, Prob 1 p.575): In the student sample program files for this chapter, you will find a text file named weather.txt. The file contains weather data for the month of January 2018. Each line in the file contains the following four pieces of data for one day: Date Precipitation High temperature Low temperature The data stored in each line is formatted in the following way: Date;Precipitation;HighTemp;LowTemp Notice that the data items are separated by semicolons. The first line in the file looks like this: 1/1/2018;0;29;10 The data stored in this line are: Date = 1/1/2018 Precipitation = 0 inches High temperature = 29 Low temperature = 10 Design a structure that has fields for the four pieces of data. In an application, read the file and store each day’s data in an instance of the structure. The structure instances should be stored in a List. Tip Use the Split method that we discussed in Chapter 8 to tokenize each line into the four pieces of data. The application should let the user select a date using a DateTimePicker control. The control should be configured so it only allows the user to select dates in January 2018. When the user selects a date, the application should display the weather data for that date.

User Alestanis
by
9.0k points

1 Answer

2 votes

Final answer:

When solving the Weather Data problem in C# using Visual Studio 2017, there could be various reasons why the provided coding solutions do not work. It is important to check for incorrect file paths, data parsing, data types, and displaying of weather data. Debugging tools and reviewing the code against the problem requirements can help identify and fix any mistakes.

Step-by-step explanation:

When attempting to solve the Weather Data problem in C# using Visual Studio 2017, there could be several reasons why the available coding solutions do not work. Some possible reasons include:

  • Incorrect file path: Make sure the program is properly accessing the weather.txt file.
  • Incorrect data parsing: Ensure that the data items are being correctly split using the semicolon delimiter.
  • Wrong data type: Check if the variables for date, precipitation, high temperature, and low temperature are of the correct data types.
  • Displaying the weather data: Make sure the program correctly displays the weather data for the selected date using the DateTimePicker control.

Review your code and compare it to the problem requirements to identify any potential mistakes. Debugging tools such as setting breakpoints and using the watch window can also be helpful in identifying and fixing issues in your code.

User Thilina Rubasingha
by
8.6k points