I need some help on what I'm working on right now I'm not asking for an answer maybe some help or a push in the right direction. Here is what I'm asked to do
"Convert your program to run from an input file instead of console input." I'm suppose to have a .txt file thats suppose to have numbers for the average rainfall and input it into what I have so far. I really don't understand Inputs/Outputs of text files and all that I tried to look up help from sites with guides that didnt really help. Can someone please help me, here is what I have so far:
#include <iostream>
#include <fstream>
#include <cstdlib>
using std::ifstream;
using std::ofstream;
using std::cout;
using std::endl;
void turnToMonth(int month);
int main()
{
ifstream inStream;
ofstream outStream;
double rainfall[12];
double averages[12];
int currentMonth;
char tableOrGraph;
char yesOrNo;
cout << "Please enter average rainfall for each month" << endl;
for (int i=0; i<12; i++) {
turnToMonth(i);
cout << ": ";
cin >> averages[i]; }
cout << "What is the number of the current month? Jan=1, Feb=2, etc." << endl;
cin >> currentMonth;
cout << "Please enter the rainfall for each month in the previous year" << endl;
int count = 0;
for (int month=currentMonth-1; count < 12; month=(month+1)%12, count++) {
turnToMonth(month);
cout << ": ";
cin >> rainfall[month]; }
cout << "\nWould you like to see a table of the results\n"
<< "or a graph? Type 't' for the table or 'g' for the graph.";
cin >> tableOrGraph;
do {
if (tableOrGraph == 't') {
cout << "Rainfall table\n\n"
<< "Month\t\tRainfall (prev. 2 months)\tDeviation\n";
for (int month=currentMonth-1, i=0; i < 12; month=(month+1)%12, i++) {
turnToMonth(month);
cout << "\t\t" << rainfall[month] << "\t\t\t";
if (rainfall[month] > averages[i])
else if (rainfall[month] < averages[i])
cout << averages[i] - rainfall[month] << endl;
else
cout << "0\n"; } }