code issue with vectors & passing info

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?

#include <cstring>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <string>
#include <vector>
#include "CinReader.h"
using namespace std;
CinReader reader;

struct entry
{
int date;
string dayOfWeek;
string text;
string timestamp;
};

//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);

if (pick == 0)
{
retrieve(May);
}
else
{
for(int = 0; i < 31; i++)
{
e2.date = i+1;
May.push_back(e2);
}
}

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;

do
{
cout << "What what would you like to do?" << endl;
cout << "[1] View entries" << endl;
cout << "[2] Add entry" << endl;
cout << "[3] Search for entries" << endl;
cout << "[0] Quit" << endl;
choice = reader.readInt(0, 3);
if (choice == 0)
{
save(e1);
quit = true;
}
else if(choice == 1)
{
cout << "Calendar Date: " << e1.date << endl;
cout << "Day of week: " << e1.dayOfWeek << endl;
cout << "Journal Entry: " << e1.text << endl;
cout << "Time: " << e1.timestamp << endl;
}
else if(choice == 2)
{
initializeEntry(e1);
}
else
{
cout << "not implemented yet" << endl;
}
}while (quit == false);
return 0;
}

//this is a function that sets up the output screen
void clear()
{
for(int i = 0; i < 26; i++)
{
cout << endl;
}
}

//function greeting the user
void greeting()
{
cout << "You will be able to enter appts or to Do List entries. \n";

cout << "Press enter to continue\n";
reader.readString();
}

void outputMonth(int start, int total)
{
cout << " May 2010 " << endl;
cout << " S M T W T F S" << endl;
cout << setw(6 * start) << "";

int i;
for (i = 1; i <= total; i++)
{
cout << setw(6) << i;
if ((i + start) % 7 == 0)
{
cout << endl;
}
}
cout << endl;
return;
}

//function for journal entry
void initializeEntry (vector<entry>& May)
{
entry e;

cout << "Please enter calendar date of the journal entry(1-31): ";
e.date = reader.readInt(1, 31);

string daysOfWeek[] = {"Monday","Tuesday","Wednesday",
"Thursday","Friday","Saturday",
"Sunday"};

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";
}
}

void clearScreen()
{
#ifdef WIN32
system("cls");
#else
system("clear");
#endif
}

Last edited on
What help? I don't see any compiler-generated errors in this...

-Albatross
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.
Yes there is a struct for the -

"//function for journal entry
void initializeEntry (vector<entry>& May)

I'm real wobbly on arrays anyway, but then vectors get thrown in & I just could only get so far
with this, any help would be appreciated

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.
Thanks that helped with some of the problems, though the whole vector thing is still confusing me
Hello fellow csci 14 student.

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)


Last edited on
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.
fixed compiler errors and thanks again to all
Topic archived. No new replies allowed.