A
Art Cummings
Morning all,
I'm stuck on a compiler error: I've included the entire error and the code
that is causing it is below. The part of the code that is creating the
error is near the top after main, where I try to initial a member of my
structural array. I wanted to be thorough in the information I provided.
Thank you
Art Cummings
"studentInfo[x].attendance=''; this is the offending code,
Compiler: Default compiler
Executing g++.exe...
g++.exe "E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp" -o
"E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.exe" -g3 -I"E:\Boot\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"
-I"E:\Boot\Dev-Cpp\include\c++\3.4.2\backward" -I"E:\Boot\Dev-Cpp\include\c++\3.4.2\mingw32"
-I"E:\Boot\Dev-Cpp\include\c++\3.4.2" -I"E:\Boot\Dev-Cpp\include" -L"E:\Boot\Dev-Cpp\lib"
-g3
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:50:41: empty
character constant
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp: In function
`int main()':
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:116: error: a
function-definition is not allowed here before '{' token
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:116: error:
expected `,' or `;' before '{' token
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:150: error: a
function-definition is not allowed here before '{' token
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:150: error:
expected `,' or `;' before '{' token
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:185: error: a
function-definition is not allowed here before '{' token
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:185: error:
expected `,' or `;' before '{' token
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:192: error:
expected `}' at end of input
Execution terminated
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <conio.h> //necessary for the _getch function
using namespace std;
const int SIZE = 15; //size for all arrays in student structure
const int ARRAYSIZE = 30; //size of array
struct Student
{
char fName[SIZE]; //array for first name
char lName[SIZE]; //array for last name
char attendance[SIZE]; //array for attendance
int days[SIZE]; //array for days
};
//function prototype for all students
int getInfo(Student[],int, int);
//function prototype for attendance
//void getAttend(Student[],int,fstream &,char *);
void getAttend(Student[],int, int);
//function prototype to display
void displayInfo(Student[],int, int);
int main()
{
Student studentInfo[ARRAYSIZE]; //define an array of 30 students
char status = 'Y';
int type=0,holdret=0;
//initial the structure to all blank strings
for (int x=0; x<ARRAYSIZE; x++)//******************THIS IS THE OFFENDING
CODE*****************************
{
{
for(int i=0;i <= SIZE; i++)
studentInfo[x].attendance='';
}
fstream student;
student.open("c:\\student.dat",ios:ut | ios::in | ios::binary |
ios::app);
cout << "Welcome to Art's attendance program \n";
cout << "To enter data, please select one of the menu numbers \n";
cout << "1. To enter student names \n";
cout << "2. To enter attendance \n";
cout << "3. To view info for students \n";
cout << "-1 to quit \n";
cin >> type;
while(type < 1 || type > 3)
{
cout << "Enter 1,2 or 3 ";
cin >> type;
}
do
{
if (type == 1)
{
holdret = getInfo(studentInfo,ARRAYSIZE,holdret);
cout << "-1 to quit, 1,2 or 3 to continue: ";
cin >> type;
}
else if (type == 2)
{
getAttend(studentInfo,ARRAYSIZE,holdret);
cout << "-1 to quit, 1,2 or 3 to continue: ";
cin >> type;
}
else
{
displayInfo(studentInfo,ARRAYSIZE,holdret);
cout << "-1 to quit, 1,2 or 3 to continue: ";
cin >> type;
}
}while (type !=-1);
student.close();
system("PAUSE");
return 0;
}
/* function header for get info */
int getInfo(Student studnt[], int x,int index)
//int getTest(Student studnt[], int x,int index)
{
//cout << "Index: " << index << endl;
int size=15,i=0,a=0, quit;
if (a != index)
{
for (a=0; a <= index; a++)
cout << a << "." << studnt[a].fName << " " << studnt[a].lName <<
endl;
}
// cout << "A: " << a << endl;
//if (a != 0)
for (i=a;i<x;i++)
{
cout << "Enter first name: " ;
cin.ignore();
cin >> studnt.fName;
cout << "Enter last name: ";
cin >> studnt.lName;
cout << "To quit type -1 type any other letter to continue: ";
cin >> quit;
if (quit == -1)
break;
}
return i;
}
void getAttend(Student studnt[], int size, int index)
{
int stud=0,day=0;
char attend;
int quit=0,a=0;
if (a != index)
{
for (a=0; a <= index; a++)
cout << a << "." << studnt[a].fName << " " << studnt[a].lName <<
endl;
}
do
{
//display the student
cout << "Chose the student you want to enter attendance:
";
cin >> stud;
cout << "Chose the day 0-15: ";
cin.ignore();
cin >> day;
cout << "Enter (P)Present,(A)Absent,(X)Excused: ";
cin >> attend;
studnt[stud].attendance[day]= attend;
cout << "To -1 or any number to continue :";
cin >> quit;
if (quit == -1)
break;
}while(quit != -1);
}
/* function header for display info */
void displayInfo(Student studnt[], int x,int index)
{
int a=0;
for (a=0; a <= index; a++)
cout << a << "." << studnt[a].fName << " " << studnt[a].lName;
for (int i=0;i<16;i++)
cout << "\t" << studnt[a].attendance;
cout << "\n";
}
I'm stuck on a compiler error: I've included the entire error and the code
that is causing it is below. The part of the code that is creating the
error is near the top after main, where I try to initial a member of my
structural array. I wanted to be thorough in the information I provided.
Thank you
Art Cummings
"studentInfo[x].attendance=''; this is the offending code,
Compiler: Default compiler
Executing g++.exe...
g++.exe "E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp" -o
"E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.exe" -g3 -I"E:\Boot\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"
-I"E:\Boot\Dev-Cpp\include\c++\3.4.2\backward" -I"E:\Boot\Dev-Cpp\include\c++\3.4.2\mingw32"
-I"E:\Boot\Dev-Cpp\include\c++\3.4.2" -I"E:\Boot\Dev-Cpp\include" -L"E:\Boot\Dev-Cpp\lib"
-g3
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:50:41: empty
character constant
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp: In function
`int main()':
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:116: error: a
function-definition is not allowed here before '{' token
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:116: error:
expected `,' or `;' before '{' token
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:150: error: a
function-definition is not allowed here before '{' token
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:150: error:
expected `,' or `;' before '{' token
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:185: error: a
function-definition is not allowed here before '{' token
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:185: error:
expected `,' or `;' before '{' token
E:\Dekalb\CIS255C\programs\attendanceProg\attendance_old.cpp:192: error:
expected `}' at end of input
Execution terminated
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <conio.h> //necessary for the _getch function
using namespace std;
const int SIZE = 15; //size for all arrays in student structure
const int ARRAYSIZE = 30; //size of array
struct Student
{
char fName[SIZE]; //array for first name
char lName[SIZE]; //array for last name
char attendance[SIZE]; //array for attendance
int days[SIZE]; //array for days
};
//function prototype for all students
int getInfo(Student[],int, int);
//function prototype for attendance
//void getAttend(Student[],int,fstream &,char *);
void getAttend(Student[],int, int);
//function prototype to display
void displayInfo(Student[],int, int);
int main()
{
Student studentInfo[ARRAYSIZE]; //define an array of 30 students
char status = 'Y';
int type=0,holdret=0;
//initial the structure to all blank strings
for (int x=0; x<ARRAYSIZE; x++)//******************THIS IS THE OFFENDING
CODE*****************************
{
{
for(int i=0;i <= SIZE; i++)
studentInfo[x].attendance='';
}
fstream student;
student.open("c:\\student.dat",ios:ut | ios::in | ios::binary |
ios::app);
cout << "Welcome to Art's attendance program \n";
cout << "To enter data, please select one of the menu numbers \n";
cout << "1. To enter student names \n";
cout << "2. To enter attendance \n";
cout << "3. To view info for students \n";
cout << "-1 to quit \n";
cin >> type;
while(type < 1 || type > 3)
{
cout << "Enter 1,2 or 3 ";
cin >> type;
}
do
{
if (type == 1)
{
holdret = getInfo(studentInfo,ARRAYSIZE,holdret);
cout << "-1 to quit, 1,2 or 3 to continue: ";
cin >> type;
}
else if (type == 2)
{
getAttend(studentInfo,ARRAYSIZE,holdret);
cout << "-1 to quit, 1,2 or 3 to continue: ";
cin >> type;
}
else
{
displayInfo(studentInfo,ARRAYSIZE,holdret);
cout << "-1 to quit, 1,2 or 3 to continue: ";
cin >> type;
}
}while (type !=-1);
student.close();
system("PAUSE");
return 0;
}
/* function header for get info */
int getInfo(Student studnt[], int x,int index)
//int getTest(Student studnt[], int x,int index)
{
//cout << "Index: " << index << endl;
int size=15,i=0,a=0, quit;
if (a != index)
{
for (a=0; a <= index; a++)
cout << a << "." << studnt[a].fName << " " << studnt[a].lName <<
endl;
}
// cout << "A: " << a << endl;
//if (a != 0)
for (i=a;i<x;i++)
{
cout << "Enter first name: " ;
cin.ignore();
cin >> studnt.fName;
cout << "Enter last name: ";
cin >> studnt.lName;
cout << "To quit type -1 type any other letter to continue: ";
cin >> quit;
if (quit == -1)
break;
}
return i;
}
void getAttend(Student studnt[], int size, int index)
{
int stud=0,day=0;
char attend;
int quit=0,a=0;
if (a != index)
{
for (a=0; a <= index; a++)
cout << a << "." << studnt[a].fName << " " << studnt[a].lName <<
endl;
}
do
{
//display the student
cout << "Chose the student you want to enter attendance:
";
cin >> stud;
cout << "Chose the day 0-15: ";
cin.ignore();
cin >> day;
cout << "Enter (P)Present,(A)Absent,(X)Excused: ";
cin >> attend;
studnt[stud].attendance[day]= attend;
cout << "To -1 or any number to continue :";
cin >> quit;
if (quit == -1)
break;
}while(quit != -1);
}
/* function header for display info */
void displayInfo(Student studnt[], int x,int index)
{
int a=0;
for (a=0; a <= index; a++)
cout << a << "." << studnt[a].fName << " " << studnt[a].lName;
for (int i=0;i<16;i++)
cout << "\t" << studnt[a].attendance;
cout << "\n";
}