I'm trying to make a simple program (I'm a noob) that reads in birthdays from a txt file, takes one new birthday in via user input, and then prints out birthdays that are upcoming within the week. It then prints the info back to the txt file. I keep getting the following error: "conversion from 'Datee*' to non-scalar type 'Datee' requested. I know that has something to do with pointers but I'm stuck. Please help and thanks in advance.
UPDATE: The first error was fixed with the help of Albert. There is now a new compile error: "request for member of non-aggregate type before '{' token. 'findDays' has not been declared". The two lines where it occurs are indicated below.
UPDATE: Second error fixed. The program is basically working now...just some tweaking and cleanup left. Thanks for the help!
Error 1: "conversion from 'Datee*' to non-scalar type 'Datee' requested."
Error 2: "request for member of non-aggregate type before '{' token. 'findDays' has not been declared".
//main.cpp
#include <iostream>
#include <fstream>
#include <string.h>
#include <cstring>
#include <ctime>
#include <sstream>
#include <vector>
#include "datee.h"
int main(int argc, char *argv[])
{
using namespace std;
char dates [10];
_strdate(dates);
char *tkn;
string name[100], month[100], day[100];
int imonth, iday, cMonth, cDay, birthDays, currentDays;
int Months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string smonth, sday, sname;
tkn = strtok(dates, "/");
imonth = atoi(tkn);
tkn = strtok(NULL, "/");
iday = atoi(tkn);
Datee *currentDate = new Datee(iday, imonth);
ifstream reader;
reader.open("birthday.txt");
string tmp;
int x = 0;
while(reader.good())
{
getline(reader, tmp);
name[x] = tmp;
getline(reader, tmp);
month[x] = tmp;
getline(reader, tmp);
day[x] = tmp;
x++;
}
cout << "enter a name: ";
getline(cin, sname);
cout << "enter a month(no zeros in front), or press <enter> to skip: ";
getline(cin, smonth);
stringstream(smonth) >> imonth;
while(imonth < 1 || imonth > 12)
{
cout << "wrong! reenter: ";
getline(cin, smonth);
stringstream(smonth) >> imonth;
}
cout << "enter a day(no zeros in front), or press <enter> to skip: ";
getline(cin, sday);
stringstream(sday) >> iday;
while(iday < 1 || iday > Months[imonth-1])
{
cout << "wrong! reenter: ";
getline(cin, sday);
stringstream(sday) >> iday;
}
int t = x-1;
name[t] = sname;
month[t] = smonth;
day[t] = sday;
ofstream writer("birthday.txt");
for(int g = x; g >= 0; g--)
{
writer << name[g] << endl;
writer << month[g] << endl;
writer << day[g] << endl;
}
int daysUntil = 0;
int h = x;
do
{
smonth = month[h];
stringstream(smonth) >> imonth;
sday = day[h];
stringstream(sday) >> iday;
Datee *birthDate = new Datee(iday, imonth);
birthDays = birthDate.findDays();
currentDays = currentDate.findDays();
daysUntil = birthDays - currentDays;
if(daysUntil >= 0 && daysUntil <= 7)
{
cout << "Birthday is coming soon! " << daysUntil << " days to go until " << name[x] << "'s birthday!" << endl;
}
h--;
}while(h >= 0);
system("PAUSE");
return 0;
}
}</enter></enter></vector></sstream></ctime></cstring></string.h></fstream></iostream>
//datee.h
<pre lang="cs">#ifndef DATEE_H_
#define DATEE_H_
<pre lang="cs">class Datee{
public:
Datee(int idays, int imths);
int findDays();
private:
int months[12];
int imths, idays, currentMonth, currentDay, totalDays;
};
#endif
//date.cpp
#include "datee.h"
Datee::Datee(int day, int mth)
{
imths = mth;
idays = day;
}
int Datee::findDays()
{
months = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
totalDays = 0;
for(int i = 0; i < imths; i++)
{
totalDays += months[i];
}
totalDays += idays;
return totalDays;
}