Ive found some old C++ project that my son did in his course for college from a few years back, and having previously enjoyed doing programming, i decided to try some of them, i consider myself mediocre at best, anyway one of his later things he was supposed to do was to design a program which should; read in 5 temperatures of the past week put them into an array, by reading the names of the past days into a separate parallel array, find the average of the temperature of the past week and finally and most importantly detect which days the the temperature of the school was below 10 and state them.
This is my code as of now, there seems to be a persistent problem with the line
83 if getline(days, day_temps[loop_counter]);
It keeps showing up as an error. I was hoping that someone could shed a little light on where i'm going wrong with it. Any help would be greatly appreciated.
#include "stdafx.h"
#include <iostream>
#include <fstream> // Allows for the use of read from/write too arrays
#include <conio.h>
#include <string>
#include <ctime>
usingnamespace std;
// Constant Varibles
int MAX =5, array_elements = 5, loop_counter;
char dat[10], tim[10];
// Declare global varibles
double day_temps[5];
// Declare Methods
void menu();
void get_temps();
void get_average();
void get_days_closed();
void initialise_the_array();
void menu()
{
// this uses a local variable
int choice;
// To Print the menu choices
do
{
cout << "\t\t -- School Temperature Imput Area --\n" << endl << endl << endl;
cout << " -----------------------------------------------" << endl;
cout << "\t1. Enter in the weekly temperatures" << endl;
cout << "\t2. Average tempretures of the week " << endl;
cout << "\t3. Days the School had been Closed " << endl;
cout << "\t4. Exit Program " << endl;
cout << " ------------------------------------------------" << endl;
cout << " Please make a selection: ";
cin >> choice;
switch (choice) // Switch statement allow the user to choose an option.
// Start of the switch statements
{
case 1:
get_temps();
break;
case 2:
get_average();
break;
case 3:
get_days_closed();
break;
} // End of switch statement
system ("cls"); // Clears the screen
}
while (choice != 4); // 4 will exit the program
}//end of methods
void initialise_days_array()
{
ifstream days ("days.txt");
for (loop_counter =0; loop_counter < MAX; loop_counter++)
{
if getline(days, day_temps[loop_counter]);
} // End if statement
{
cout << "Unable to read file!!" <<endl <<endl ;
cout << "Press any key to continue. ";
_getch();
cout << endl << endl;
} // end the else statement
days.close();
} // end of initialise_days method
void get_temps()
{
system("cls");
for (loop_counter = 0; loop_counter < MAX; loop_counter++)
{
cout << "Please enter the temperature for " << day_temps[loop_counter] << ":";
cin >>day_temps[loop_counter];
cout << endl;
} // end of for loop
} // end of get_temps method
void get_average()
{
double total, average;
int count;
total = 0;
for (count = 0; count < MAX; count ++)
total = (total + day_temps[count]);
average = (total / 5);
cout << endl << "The average temperature for the week was " << average << "degrees";
_getch();
}
void get_days_closed()
// states the days the school was closed
{
int count;
string line;
// Opens text file
ifstream days("days.txt");
for (count =0; count < MAX; count ++)
if(day_temps[count] <10) // States the days the school had been closed
cout << endl << "The school was CLOSED on";
else // states the school was closed on that day
{
cout << endl << endl << "The school was OPEN on:";
if (days.is_open())
_getch();
}
_getch();
}
OK Ive removed the the semi colon, but still error C2061: syntax error : identifier 'getline'
Comes up and im still completely stumped with what to do.