| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hey all! I have been running myself into the ground on this program for class. If anyone out there can help me with this
that would be a life saver!! I have gotten it down to 7 errors, but not sure how to fix them. These are the errors: student.cpp(93) : error C2041: illegal digit '8' for base '8' student.cpp(107) : error C2041: illegal digit '9' for base '8' student.cpp(124) : error C2041: illegal digit '8' for base '8' student.cpp(131) : error C2041: illegal digit '9' for base '8' student.cpp(206) : error C2065: 'stuid' : undeclared identifier student.cpp(226) : error C2181: illegal else without matching if student.cpp(234) : error C2601: 'writeheadings' : local function definitions are illegal Error executing cl.exe. Here is my Program.... Please if anyone can help me with this and let me know just what i am doing worng would be a great help!! //studentid.cpp # include <iostream> # include <iomanip> # include <fstream> using namespace std; /* This program will read the data file of students and the date they were born. It will print out the student ID and the date which they were born. It will also output the student ID of the oldest student and how many students were born on Feb 29. This program was written by Steven Pattie and is Graded HW#2*/ class student { private: int stuid; int birthday; int birthmonth; int birthyear; int ageyear; int agemonth; int ageday; static int countstudent; static int countoldest; static int countfeb29; static int day; static int month; static int year; static int oldestyear; static int oldestmonth; static int oldestday; static int oldestid; public: student () {} student (int month, int day) { birthmonth = month; birthday = day; } int getstudentid() {return stuid;} void readata (ifstream& data) { data >> stuid >> birthday >> birthmonth >> birthyear; } void writestudentcount (ofstream& results) { results << "The total count was " << countstudent << " students. \n"; } void writeresults (ofstream& results) { results << stuid << birthday << birthmonth << birthyear <<endl; } void writegiven (ofstream& results) { results << countfeb29 <<" Were born on Feb 29th. \n"; } char datavalid (); void calcage(); void writeoldest (); void oldest (); }; int student::countstudent; int student::countoldest; int student::countfeb29; int student::day; int student::month; int student::year; int student: ldestyear;int student: ldestmonth;int student: ldestday;int student: ldestid;char student::datavalid () { char valid; countstudent ++; if (birthyear > year) cout << "Year entered is incorrect, please check data file. \n"; else if (birthmonth <= 0 || birthmonth > 12) cout << " Birth month data is incorrect, please check data file. \n"; else if (birthmonth ==01 || birthmonth==03 || birthmonth==05 || birthmonth==07 || birthmonth==08 || birthmonth==10 || birthmonth==12) if (birthday >31 || birthmonth<= 0) cout <<"Birth day is incorrect, please check data file. \n"; else valid = 'T'; else if (birthmonth = 02) if (birthday >29 || birthmonth<=0) cout <<"Birth day is incorrect, please check data file. \n"; else valid = 'T'; else if (birthmonth ==04 || birthmonth==06 || birthmonth==09 || birthmonth==11) if (birthday >30 || birthday<= 0) cout <<"Birth day is incorrect, please check data file. \n"; else valid = 'T'; return valid; } void student::calcage () { ageyear = year - birthyear; if (agemonth >= month) agemonth = month - birthmonth + 12; else agemonth = month - birthmonth; if (birthmonth ==01 || birthmonth==03 || birthmonth==05 || birthmonth==07 || birthmonth==08 || birthmonth==10 || birthmonth==12) if (birthday > day) ageday = day - birthday +31; else ageday = day - birthday; else if (birthmonth ==04 || birthmonth==06 || birthmonth==09 || birthmonth==11) if (birthday > day) ageday = day - birthday +30; else ageday = day - birthday; else if (birthmonth == 02) if (birthday == 29) if (day < 29) ageday = day - birthday +29; else ageday = day - birthday; else if (birthday > day) ageday = day - birthday +28; else ageday = day - birthday; } void student: ldest(){ if (oldestyear < ageyear) { oldestyear = birthyear; oldestmonth = birthmonth; oldestday = birthday; oldestid = stuid; } else if (oldestyear == ageyear) if (oldestmonth < agemonth) { oldestmonth = birthmonth; oldestday = birthday; oldestid = stuid; } else if (oldestmonth == agemonth && oldestday < ageday) { oldestday = birthday; oldestid = stuid; } else if (oldestday = ageday) countoldest ++; } void student::writeoldest() { if (countoldest <= 1) cout << "The oldest student is " << oldestid << "born " << oldestyear << oldestmonth << oldestday; else cout << "There were " << countoldest << "students that tied for being the oldest. \n"; } void main () { student stu; student base(02, 29); void writeheadings (ofstream& results); ifstream data; data.open ("data.txt"); //open the file named data ofstream results; results.open ("results.txt"); //open the file named results stu.getstudentid (); if (!data || !results) cout << "check data file. \n"; else writeheadings (results); stu.readata (data); // calls the read function in public for the first read if (stuid = 000) cout << "First record is dummy record. \n"; else while (stuid !=000) { if (stu.datavalid () =='T') { stu.calcage (); stu.oldest (); stu.writeresults (results); } else cout <<"Data for students is invalid. \n"; stu.readata (data); // calls the read function in public } { base.writestudentcount (results); base.writeoldest (); base.writegiven (results); } else cout << "One of the data files failed to open. \n"; data.close (); results.close (); void writeheadings (ofstream& results) // This will write out the headings for this program { results << "Student ID" << " Birthdate " << endl; } } |
|
#2
|
|||
|
|||
|
One of the main problems is putting a zero before numbers since this tells the compiler that the number is in octal. So instead of using 01, 02 etc just use 1, 2 and so on.
I would highly recommend you read a tutorial or two about formatting code which will help you avoid missing braces and having else statements with no matching if etc. When you post code on this forum please format it using code tags to make it easier to read. That way you're more likely to get a response. -KM- |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Running myself into the ground!! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|