Several lines have multiple errors, I built this in Codeblocks & it won't let me
just cut and past the whole block of errors from there. I reproduced them here with line# & actual code & then the error for that line, help?
IN //functions for use by program
LINE #43: void search (vector<day> May);
error:'day' was not declard in this scope
error: template argument 1 is invalid
error: template argument 2 is invalid
ISO C++ forbids declaration of 'May' with no type
IN FUNCTION INT MAIN()
LINE #109: save(e1);
error: conversion from "entry' to non-scalar type 'std::vector<entry, std::allocator<...
LINE #235: void search (vector<day> May)
error: expected primary-expression before '&' token
error: 'day' was not declared in this scope
error: template argument 1 is invalid
error: template argument 2 is invalid
LINE #236: {
error: ISO C++ forbids declaration of 'May" with no type
IN void search (vector<day> May)
LINE #241: for (int i = 0; i < May.size(); i++;
error: request for member 'size' in "May', which is of non-class type 'int'
error: using obsolete binding at 'i'
LINE #243: int pos = May[i].entry.find(word);
error: name lookup of 'i' changed for new ISO 'for' scoping
error: invalid types 'int[int]' for array subscript
LINE #246: cout << May[i].date << ": ";
LINE #247: cout << May[i].entry << "\n";
error: invalid types 'int[int]' for array subscript
IN void print (vector<day> May)
LINE #252: void print (vector<day> May)
error: 'day' was not declared in this scope
error: template argument 1 is invalid
error: template argument 2 is invalid
LINE #253: {
error: ISO C++ forbids declaration of 'May" with no type
LINE #255: for (int i = 0; i < May.size(); i++)
error: request for member 'size' in 'May" which is of non-class type 'int'
LINE #257: cout << month[May].date << "; ";
error: 'month' was not declared in this scope
new to C++ have errors in this when I compile got some partial help & all this popped up!! Too inexperienced to understand all the fixes, did some, can someone help?
//functions for use by program
void clear();
void greeting();
void outputMonth(int start, int total);
void initializeEntry (vector<entry>& May);
void save (vector<entry> May);
void retrieve (vector<entry>& May);
void clearScreen();
void search (vector<day> month);??
//function allowing your program to start, prompts user for input and
//outputs information to user, uses structs, calls functions, cleans up arrays when done
int main()
{
greeting();
int i = 0;
int days = 0;
int pick = 0;
entry e2;
vector <entry> May;
cout << "What would you like to do in your journal?" "\n";
cout << "[0] Retrieve prior journal entries." "\n";
cout << "[1] Start a new journal." "\n";
pick = reader.readInt(0,1);
do
{
cout << "We are creating a calendar for May 2010." "\n";
cout << "What day is the 1st on for this month? " "\n\n";
cout << "Pick from the menu & enter the number: " "\n\n";
cout << "Sun=0 ,Mon=1 ,Tues=2 ,Wed=3 ,Thu=4 ,Fri=5 ,Sat=6" "\n";
cin >> i;
}
while ((i < 0) || (i > 7));
do
{
cout << "input the number of days in this month: " "\n\n";
cin >> days;
}
while ((days > 31) || (days < 28));
outputMonth(i, days);
// e1 is an instance of entry
entry e1;
int choice = 0;
bool quit = false;
for (int i = 0; i < 7; i++)
{
cout << "[" << (i + 1) << "] " << daysOfWeek[i] << "\n";
}
cout << "select day of week from the menu & enter the corresponding number: ""\n\n";
e.dayOfWeek = daysOfWeek[reader.readInt(1,7)-1];
cout << "Type your appt or to do List entry:\n";
e.text = reader.readString();
cout << "Enter the time (e.g.,1:45pm,2:01am ): ";
e.timestamp = reader.readString();
}
//function to save data to a text file
void save (vector<entry> May)
{
ofstream fout("journal.txt");
if (!fout.fail())
{
for (int i = 0; i < May.size(); i++)
{
fout << May[i].date << endl;
fout << May[i].dayOfWeek << endl;//May is the journal [i]= a page in the journal
fout << May[i].text << endl;
fout << May[i].timestamp << endl;
}
fout.close();
}
}
//funtion to retrive data from a text file, saving entries to a vector
void retrieve (vector<entry>& May)
{
ifstream fin("journal.txt");
if (!fin.fail())
{
for (int = 0; i < 31; i++)//can't use May.size because vector for May doesn't exist yet
{
entry e;
string dateString;
getline(fin, dateString);
e.date = atoi(dateString.c_str());
getline(fin, e.dayOfWeek);
getline(fin, e.text);
getline(fin, e.timestamp);
May.push_back(e);//push entry into slot to save
}
fin.close();
}
}
void search (vector<day> month)
{
cout << "\nPlease enter the word you are searching for: ";
string word = reader.readString();
cout << "\nSearching for \"" << word << "\"...\n\n";
for (int i = 0; i < month.size(); i++;
{
int pos = month[i].entry.find(word);
if (pos != string::npos)
{
cout << month[i].date << ": ";
cout << month[i].entry << "\n";
}
}
}
void print (vector<day> month)
{
clearScreen();
for (int i = 0; i < month.size(); i++)
{
cout << month[May].date << "; ";
cout << month[May].entry << "\n";
}
}
After a quick glance, it looks like several of your functions are declared and defined as taking a vector as an argument, but in your code you pass them a struct.
LINE #43: void search (vector<day> May);
error:'day' was not declard in this scope
I think you want vector<entry> May there.
LINE #109: save(e1);
error: conversion from "entry' to non-scalar type 'std::vector<entry, std::allocator<...
Like I said earlier, you're trying to pass a struct to a function that accepts arguments of type vector.
LINE #235: void search (vector<day> May)
error: 'day' was not declared in this scope
I think you want vector<entry> May there.
LINE #257: cout << month[May].date << "; ";
error: 'month' was not declared in this scope
The problem here is that vector<entry> month was not declared anywhere. You seemed to start using the vector month instead of vector may halfway through the program.
I noticed a minor error in your retrieve function. You are missing an i
it should be:
for (int i = 0;
also in you are missing a < in your print function
for (int i = 0; i < month.size(); i++)
should be
for (int i = 0; i << month.size(); i++)
Also it might be easier to try and get it working one piece at a time
if you have non essential functions that are not working right than comment them out for the moment
this will allow you to isolate an area and get it working
as one final peace of advice try declaring a variable for number of days in the month and using it in your for loops
or
just type in 31 (the number of days in may)
Thanks for the feedback all. LoctheToker maybe we can do private conversation since appears we are in same class CSCI 14? I could use some help sometime & I can only make the Lab 1-1.5 hrs as I have other class that conflict. If ok, answer here & I will add for private info on profile.