Write your question here.
Well I am trying to create a Structure array of [12] that is populated by the function below and prints out using another function in a readable way.
well I have gotten to the point where I am creating a single instance and I can't get any real data to print, I instead get...and that's just with the one function.
Mont
0
6356664
1.21985e+032
I have been stabbing at it for hours and hours...its due tomorrow at midnight so I thought I might reach out to the community, I try not to do this too often.
Yes it's Homework... this assignment though is making me insane. Thanks for any help, sorry the horrendous code.....
#include <iostream>
#include <iomanip>
#include <fstream>
usingnamespace std;
// Structure declaration
struct Weather
{
char Month[3];
int Aht;
int Alt;
float Mprec;
};
// Function prototype
Weather getInfo();
int main(){
Weather c[12]; // structure variable
c[12] = getInfo();
return 0;
}
Weather getInfo()
{
Weather W; // Temporary structure variable
ifstream inputFile;
inputFile.open("data.txt");
if (inputFile.is_open()) {
// While the file is good
while (inputFile.good() ) {
inputFile >> W.Month;
inputFile >> W.Aht;
inputFile >> W.Alt;
inputFile >> W.Mprec;
cout << W.Month << '\n';
cout << W.Aht << '\n';
cout << W.Alt << '\n';
cout << W.Mprec << '\n';
}
inputFile.close();
}
// Return the temporary variable.
return W;
}
The data.txt file is as follows
Month High Low Precipitation
Jan 33 18 0.87
Feb 39 21 0.71
Mar 50 28 0.98
Apr 58 33 1.22
May 67 40 2.01
Jun 75 47 2.09
Jul 86 51 0.98
Aug 85 50 1.18
Sep 73 42 1.18
Oct 58 32 0.87
Nov 42 25 1.02
Dec 31 17 1.02