Question: Reading and displaying text file rainfall.txt. Do not assume the number of months. Instead, continue to read month names and rainfall amounts until the file

Reading and displaying text file "rainfall.txt.

"Do not assume the number of months. Instead, continue to read month names and rainfall amounts until the file is empty. You can assume that if a name is provided it will be followed by a rainfall amount. That means that you can test if the file is empty (using a while loop) by reading the name of the next month (see program 5-20) As you loop over the months in the file, keep a running total of rainfall amounts and a count of months processed. The count of months processed will be needed to calculate the average. Your output should be (using the names and amounts read from the file, of course):"

output should look like this:

Month Amount -------------------------------------------------------------------------- August 2.45 September 1.22 October 2.13 November 1.01 Average Rainfall: 1.70

Now here's my code so far, and it's not working:

#include "stdafx.h" #include #include #include using namespace std;

int main() { ifstream myfile("rainfall.txt"); //string textf[50];

myfile.open("rainfall.txt");

//error check if (myfile.fail()) { cout << "file read failure, check source" << endl; }

string textf[50]; myfile >> textf;

return 0;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!