You are using a version without Ads of this website. Please, consider donating:

### Reading doubles into an Array

Okay here's the situation I have 70 years worth of data separated by year which are integer data values, that match up with 12 double values that represent weather data. I am lost on how to read the data in for the given year the user enters and have the corresponding weather data also be printed. Good karma for anyone who can help me!
What is weather data?
i assume the values are seperated by a coma, semicolon, new line, or anything else.
just use the seperation character to make a difference between year and data
Weather data is a double. I know this is asking a lot but if someone could present an example implementing a for loop, I'd be eternally grateful.
What does it contain? Temperature, Moisture, or anything else?
Just temperature and year and example would be the data stored in the .txt file like this :

1940 18.4 24.8 27.4 42.4 57.8 66.0 72.0 70.0 61.6 47.3 38.9 30.8 1941 22.8 22.4 25.2 49.7 58.2 68.7 73.9 67.4 64.1 52.2 43.1 31.8 1942 24.4 20.4 35.6 50.1 59.8 67.8 71.0 69.2 62.9 52.4 39.4 24.4 1943 20.4 26.4 31.8 38.6 56.2 70.8 71.8 68.4 60.6 48.6 37.0 25.4 1944 28.6 24.0 29.7 40.2 63.2 67.0 72.6 72.5 62.6 49.4 40.7 23.2 1945 15.2 25.1 43.8 50.4 51.2 64.6 70.2 69.3 64.3 50.0 40.6 23.0 1946 26.2 23.4 43.2 44.4 55.6 65.2 70.5 65.8 64.0 56.8 43.7 30.6

Last edited on
You'll need to:
0- Create a variable which stores your specific year input.
1- Define an array which contains weather data
`double weatherData[12]; //12 values for 12 months `
2- Input? Create a 12-time loop using a index variable. It should look like this:
 ``123456`` ``````for(int i =0; i < 12;i++) { printf("Input weatherData[%d] - Month %d : ",i,i + 1); cin >> weatherData[i]; printf("\n"); }``````

Three (If you need), print your results directly on the screen using 12-time loop and screen printing functions (cout, printf)...l
Four (If you need), log your results and specific year input into a txt file, using a 12-time loop.
Edit : You may put all code in while contidion loop to log re-input the values multiple times.
Good luck! :)
Last edited on
Topic archived. No new replies allowed.