? can anyone check my solution please
write a program that calculates the average rainfall for three months. The program should ask the user to enter the name of each month, such as June or July, and the amount of rainfall (in millimeters) that fell each month. The program should display a message similar to the following:
The average rainfall for June, July, and August is 6.72 millimeters
* modify the program you wrote , so it reads its input from a file instead of the keyboard
# include <iostream>
#include <iomanip>
using namespace std;
int main()
{
char month1[8], month2[8], month3[8];
double rainfall, avg_Rainfall;
double totalRainfall = 0;
cout << "Enter three consecutive months: " << endl;
cin >> month1 >> month2 >> month3;
cout << "How much inches of rain fell in " << month1 << "?" << endl;
cin >> rainfall;
totalRainfall += rainfall;;
cout << "How much inches of rain fell in " << month2 << "?" << endl;
cin >> rainfall;
totalRainfall += rainfall;
cout << "How much inches of rain fell in " << month3 << "?" << endl;
cin >> rainfall;
totalRainfall += rainfall;
avg_Rainfall = totalRainfall / 3;
system("pause");
return 0;
}
1wirte a program that asks the user to enter 5 floating point numbers . the program should create a file and save all 5 numbers to the file
2the program should open the file created in program 1 and ask the user to enter another 5 floating points numbers and save all 5 numbers to the file , calculate the average of all 10 numbers in the file and finally display the average and save the the average file
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
float num1, num2, num3, num4, num5;
cout << "Enter five numbers, each separated by a space (decimals allowed)" << endl;
cin >> num1 >> num2 >> num3 >> num4 >> num5;
ofstream outputFile;
outputFile.open("demofile.txt");
cout << "Now writing those five numbers to demofile.txt file." << endl;
outputFile << num1 << endl;
outputFile << num2 << endl;
outputFile << num3 << endl;
outputFile << num4 << endl;
outputFile << num5 << endl;
outputFile.close();
cout << "Finished writing those five numbers to demofile.txt file." << endl;
return 0;
}
2
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
float num1, num2, num3, num4, num5, sum;
ifstream inFile;
inFile.open("demofile.txt");
cout << "Now reading information from demofile.txt..." << endl;
inFile >> num1;
cout << "num1 is " << num1 << endl;
inFile >> num2;
cout << "num2 is " << num2 << endl;
inFile >> num3;
cout << "num3 is " << num3 << endl;
inFile >> num4;
cout << "num4 is " << num4 << endl;
inFile >> num5;
cout << "num5 is " << num5 << endl;
inFile.close();
cout << "Closed demofile.txt file." << endl;
sum = num1 + num2 + num3 + num4 + num5;
cout << "The sum of these five numbers are " << sum << endl;
return 0;
{