Click here to Skip to main content
14,644,614 members
Rate this:
Please Sign up or sign in to vote.
See more:
while compiling i got an exception 13 error. can u help me fix it.
i used turbo c++ on win xp.
i'm a plus two student and haven't gone into an in-depth study of the language.this code is my project 4 boards.
on compiling the code,the error message was as follows:
general protection fault at 0AD7:0A31 ERROR CODE-3A00
ax=3A00,bx=029C,cx=08CA,dx=3A00,di=0002,si=E2DE
ds=069F limit=FFFF segment# 004D C:\TC\BIN\TC.EXE
es=13aF limit=044F segment#
cs=0A07 limit=1D3B segment# 00A9 C:\TC\BIN\TC.EXE
ss=069F limit=FFFF segment# 004D C:\TC\BIB\TC.EXE
error code=3A00 limit=INVL segment#
wen i removd d class Date part of d code,the exception error didn't show up.
the code is as follows:
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<string.h>
#include<ctype.h>
#include<stdio.h>
ifstream flight("Flights.dat",ios::binary);
ifstream hotel("Hotels.dat",ios::binary);
ifstream rail("Rails.dat",ios::binary);
ifstream bus("Bus.dat",ios::binary);
ifstream holiday("Holidays.dat",ios::binary);
ifstream place("Places.dat",ios::binary);
ifstream booking("Booked.dat",ios::binary);
ofstream book("Booked.dat",ios::binary,ios::app);
ifstream read_record("Record.dat",ios::binary);
ofstream write_record("Record.dat",ios::binary,ios::app);
int leave=0;
int destination=0;

int depart_time=0;
int adults=0;
int children=0;
int infants=0;
int j=0;
int c=0;
int duration=0;
float f=0.0;
class Place
{
private:
char name[20];
int code;
public:
void assign()
{
cout<<"Name:";
gets(name);
place.seekg(0,ios::beg);
code=6000+(place.tellg()/sizeof(Place))+1;
}
int get_code()
{
return code;
}
void display()
{
puts(name);
cout<<"("<<code<<")";
}
};
class Date
{
private:
int day;
int month;
int year;
public:
void enter_date();
void copy(Date d);
void display()
{
cout<<day<<"."<<month<<"."<<year;
}
void refresh()
{
day=0;
month=0;
year=0;
}
int get_day()
{
return day;
}
int get_month()
{
return month;
}
int get_year()
{
return year;
}
};
void Date::enter_date()
{
int correct=0;
do{
cout<<"Day:";
cin>>day;
cout<<"Month:";
cin>>month;
cout<<"Year:";
cin>>year;
/* if((day>0)||(day<32)||(month>0)||(month<13)||(year>2009)||(year<2014))
{
if(((month==4)||(month==6)||(month==11)||(month==9))&&(day==31))
{
cout<<"Invalid date.\nPlease re-enter correct date:\n";
continue;
}
else if((month==2)&&(day>28))
{
if((year==2012)&&(day==29))
{
cout<<"Date verified:Valid.\n";
correct=1;
continue;
}
else
{
cout<<"Invalid date.\nPlease re-enter corrcet date:\n";
continue;
}
}
else
{
cout<<"Date verified:Valid.\n";
correct=1;
continue;
}
}
else
{
cout<<"Invalid date.\nPlease re-enter correct date:\n";
continue;
}
}while(correct==0);
} */
void Date::copy(Date d)
{
day=d.get_day();
month=d.get_month();
year=d.get_year();
}
Date date;
class Password
{
private:
char pass[20];
public:
Password()
{
strcpy(pass,"9830182259");
}
void change_pass(Record r);
int compare_pass(char p[20]);
};

void Password::change_pass()
{
char new_pass[20];
cout<<"Enter current password\n";
gets(new_pass);
if(compare_pass(new_pass))
{
cout<<"Enter new password\n";
gets(new_pass);
strcpy(pass,new_pass);
cout<<"Password changed successfully\n";
}
else
cout<<"Invalid password\nAccess Denied!!\n";
}


int Password::compare_pass(char p[20])
{
for(int i=0;i<20;i++)
{
if(pass[i]==p[i])
continue;
else
return 0;
}
return 1;
}
Password *p=new Password();
ofstream write_pass("Password.dat",ios::binary);
write_pass.write((char*)&p,sizeof(p));
class Record
{
private:
Date d;
int code;
int left;
public:
int compare(Record r)
{
if((r.get_date().get_day()==d.get_day())&&(r.get_date().get_month()==d.get_month())&&(r.get_date().get_year()==d.get_year())&&(r.get_code()==code))
return 1;
else
return 0;
}
void get(int a,int b)
{
code=a;
d.copy(date);
left=b;
}
void copy(Record r)
{
d.copy(r.get_date());
code=r.get_code();
left=r.get_left();
}
Date get_date()
{
return d;
}
int get_code()
{
return code;
}
int get_left()
{
return left;
}
};
class Flight
{
private:
int f_code;
char op[20];
int operator_code;
Place from;
Place to;
int time;
int time_code;
int fare;
int economy_seats;
int business_seats;
public:
void check_availability();

void assign()
{
flight.seekg(0,ios::end);
f_code=1000+(flight.tellg()/sizeof(Flight))+1;
cout<<"\nOperator:";
gets(op);
cout<<"\nDeparure:";
from.assign();
cout<<"\nArrival:";
to.assign();
cout<<"\nDeparture time:";
cin>>time;
if(time>500 && time<=1200)
time_code=1;
else if(time>1200 && time<=1800)
time_code=2;
else if(time>1800 && time<=0)
time_code=3;
else
time_code=4;
cout<<"\nFare: Rs.";
cin>>fare;
cout<<"\nEconomy seats:";
cin>>economy_seats;
cout<<"\nBusiness seats:";
cin>>business_seats;
}
int check(int k,int l)
{
if((k==from.get_code())&&(l==to.get_code()))
return f_code;
else
return 0;
}
int get_code()
{
return f_code;
}
int get_time_code()
{
return time_code;
}
int get_fare()
{
return fare;
}
void short_display()
{
cout<<"Flight code:"<<f_code<<"\t";
puts(op);
}
void display()
{
cout<<"Flight code:"<<f_code<<"\t";
puts(op);
cout<<"\nFrom:";
from.display();
cout<<"\nTo:";
to.display();
cout<<"\nDate:";
date.display();
cout<<"\nTime:"<<time<<"\nFare:Rs.";
f=fare*adults*1.0+fare*children*0.5+fare*infants*0.1;
cout<<f<<endl;
}
};
void Flight::check_availability(Record r)
{
Record rec;
r.get(f_code,economy_seats+business_seats);
read_record.seekg(0,ios::beg);
while(read_record)
{
read_record.read((char*)& rec, sizeof(rec));
if(rec.compare(r))
{
r.copy(rec);
break;
}
}
}
class Hotel
{
private:
int h_code;
char name[20];
int star;
Place p;
int rooms;
int avg_daily_rate;
int xtra_perday;
char amenities[200];
public:
void check_availability(Record r);
void assign()
{
hotel.seekg(0,ios::end);
h_code=2000+(hotel.tellg()/sizeof(Hotel))+1;
cout<<"Name:";
gets(name);
cout<<"Star rating:";
cin>>star;
cout<<"Location:";
p.assign();
cout<<"Number of Rooms:";
cin>>rooms;
cout<<"Average daily rate: Rs.";
cin>>avg_daily_rate;
cout<<"Extra per day:Rs:";
cin>>xtra_perday;
cout<<"Amenities:";
gets(amenities);
}
void short_display()
{
puts(name);
cout<<"("<<h_code<<")\t"<<star<<" star\n";
}
void display()
{
puts(name);
cout<<"("<<h_code<<")\n"<<star<<" star\n"<<"Avg daily rate:Rs."<<avg_daily_rate;
cout<<"\nAmenities:";
puts(amenities);
cout<<endl;
}
int get_code()
{
return h_code;
}
int get_location()
{
return p.get_code();
}
};
void Hotel::check_availability(Record r)
{
Record rec;
r.get(h_code,rooms);
read_record.seekg(0,ios::beg);
while(read_record)
{
read_record.read((char*)& rec, sizeof(rec));
if(rec.compare(r))
{
r.copy(rec);
break;
}
}
}
class Rail
{
private:
int r_code;
char train[30];
int seats;
Place from;
Place to;
int time[10];
Place stations[10];
float fare[10];
public:
void assign();
void check_availability(Record r);
int check(int x,int y);

int get_code()
{
return r_code;
}
void short_display()
{
cout<<"Train code:"<<r_code<<"\tName:";
puts(train);
}

};
void Rail::assign()
{
rail.seekg(0,ios::end);
r_code=3000+(rail.tellg()/sizeof(Rail))+1;
cout<<"Train name:\n";
gets(train);
cout<<"\nEnter number of seats:";
cin>>seats;
cout<<"\nStarting location:";
from.assign();
cout<<"\nDestination station:";
to.assign();
cout<<"\nEnter stoppages:";
for(int i=0;i<10;i++)
{
cout<<"\nStation "<<(i+1);
stations[i].assign();
cout<<"\nTime:";
cin>>time[i];
cout<<"\nFare from previous station: Rs.";
cin>>fare[i];
}
}
int Rail::check(int x,int y)
{
int result=0;
int d=0;
if(x==from.get_code())
result=1;
else
{
for(d=0;d<10;d++)
{
if(x==stations[d].get_code())
result=1;
}
}
if(result)
{
result=0;
for(;d<10;d++)
{
if(y==stations[d].get_code())
result=1;
}
if(!result)
{
if(y==to.get_code())
result=1;
}
}
if(result)
return r_code;
else
return 0;
}
void Rail::check_availability(Record r)
{
Record rec;
r.get(r_code,seats);
read_record.seekg(0,ios::beg);
while(read_record)
{
read_record.read((char*)& rec, sizeof(rec));
if(rec.compare(r))
{
r.copy(rec);
break;
}
}
}
class Bus
{
private:
int b_code;
char op[20];
int operator_code;
Place from;
Place to;
Place stoppages[10];
int time[10];
float fare[10];
int seats;
public:
int check(int x,int y);
void check_availability(Record r);
void assign();
int get_code()
{
return b_code;
}
void short_display()
{
cout<<"Bus code:"<<b_code<<"\tOperator:";
puts(op);
}
};
void Bus::assign()
{
bus.seekg(0,ios::end);
b_code=3000+(bus.tellg()/sizeof(Bus))+1;
cout<<"Train name:\n";
gets(op);
cout<<"\nEnter number of seats:";
cin>>seats;
cout<<"\nStarting location:";
from.assign();
cout<<"\nDestination station:";
to.assign();
cout<<"\nEnter stoppages:";
for(int i=0;i<10;i++)
{
cout<<"\nStation "<<i+1;
stoppages[i].assign();
cout<<"\nTime:";
cin>>time[i];
cout<<"\nFare from previous station: Rs.";
cin>>fare[i];
}
}
int Bus::check(int x,int y)
{
int result=0;
int d=0;
if(x==from.get_code())
result=1;
else
{
for(d=0;d<10;d++)
{
if(x==stoppages[d].get_code())
result=1;
}
}
if(result)
{
result=0;
for(;d<10;d++)
{
if(y==stoppages[d].get_code())
result=1;
}
if(!result)
{
if(y==to.get_code())
result=1;
}
}
if(result)
return b_code;
else
return 0;
}
void Bus::check_availability(Record r)
{
Record rec;
r.get(b_code,seats);
read_record.seekg(0,ios::beg);
while(read_record)
{
read_record.read((char*)& rec, sizeof(rec));
if(rec.compare(r))
{
r.copy(rec);
break;
}
}
}
class Booked
{
private:
int ref_no;
int code;
int l;
int dest;
char names[6][20];
float fare;
char credit_card[16];
int conf;
Date d;
int preference;
char e_mail[25];
public:
void display();
int confirm(int k, int l);
int get_reference()
{
return ref_no;
}
};
void Booked::display()
{
cout<<"Reference No.:"<<ref_no<<endl;
cout<<"Travellers:\n";
for(int a=0;a<6;a++)
{
cout<<(a+1)<<". ";
puts(names[a]);
}
cout<<"Total fare- Rs."<<fare;
cout<<"Date:";
d.display();
}
int Booked::confirm(int k, int l)
{
l=leave;
dest=destination;
d.copy(date);
preference=l;
code=k;
k=0;
fare=f;
cout<<"\nPlease enter the names of the travellers(excluding infants):\n";
cout<<"\nWhen done enter 0\n";
do
{
gets(names[k]);
k++;
}while(names[k][0]!='0');
booking.seekg(0,ios::end);
ref_no=7000+(booking.tellg()/sizeof(Booked))+1;
cout<<"\nCredit card number:";
gets(credit_card);
cout<<"e-mail id:\n";
gets(e_mail);
if(k-1!=0) conf=1;
else conf=0;
return conf;
}
class Holiday
{
private:
Place leave;
Place destination;
char theme[20];
int theme_code;
int h_code;
int duration;
float fare;
char description[300];
public:
void assign()
{
holiday.seekg(0,ios::end);
h_code=5000+(holiday.tellg()/sizeof(Holiday))+1;
cout<<"\nDeparture:";
leave.assign();
cout<<"\nDestination:";
destination.assign();
cout<<"\nTheme:";
gets(theme);
cout<<"\nDuration:";
cin>>"duration";
cout<<"\nFare: Rs.";
cin>>fare;'
cout<<"\nDescription:";
gets(description);
}
void short_display()
{
cout<<"Destination:";
p.display();
cout<<"\tCode:"<<h_code;
cout<<"\tDuration:"<<duration<<" days";
}
void display()
{
cout<<"Destination:";
destination.display();
cout<<"\nFlight will be provided from ";
leave.display();
cout<<"\nHoliday theme:";
puts(theme);
cout<<"\nDuration:"<<duration<<" days\nFare: Rs."<<fare<<" per person\nDuration";
}
};


void menu()
{
cout<<"1. Flights"<<endl;
cout<<"2. Hotels"<<endl;
cout<<"3. Railways"<<endl;
cout<<"4. Bus"<<endl;
cout<<"5. Holidays"<<endl;
cout<<"6. Check status"<<endl;
cout<<"7. Login(for authorised personnel only)";
cout<<"8. Exit";
}
void login_menu()
{
cout<<"\n Login menu";
cout<<"1. Add new flight\n";
cout<<"2. Add new hotel\n";
cout<<"3. Add new train\n";
cout<<"4. Add new bus\n";
cout<<"5. Add new holiday\n";
cout<<"6. Add new place\n";
cout<<"7. Change password\n";
cout<<"8. Return to previous menu\n";
cout<<"Enter your option(1-7):";
}
void display_cities()
{
Place p;
j=1;
place.seekg(0);
while(!place)
{
place.read((char*)& p, sizeof(Place));
cout<<j<<".";
p.display();
cout<<endl;
j++;
}
cout<<"Enter the city code:";
}
void read_info(int ch)
{
if(ch!=2||ch!=5)
{
cout<<"Leaving from:\n";
display_cities();
cin>>leave;
}
cout<<"\nGoing to:\n";
display_cities();
cin>>destination;
if(ch!=2)
cout<<"Departure date:";
else
cout<<"Arrival date:";
date.enter_date();
if(ch==1)
{
cout<<"\nChoose departure time\n1. 0500-1200\n2. 1200-1800\n3. 1800-0000\n4. 0000-0500\n";
cin>>depart_time;
}
cout<<"Travellers(upto 6 per booking):\n";
cout<<"Adults(12+):";
cin>>adults;
cout<<"\nChildren(2-11):";
cin>>children;
cout<<"\nInfants(0-2):";
cin>>infants;
}
void holiday_info()
{
cout<<"Destination:";
display_cities();
cin>>destination;
cout<<"\nDuration:\n1.1-4 days\n2.4-7 days\n3.7+ days";
cin>>duration;
}
int search_flight()
{
Flight f;
int a1;
int found=0;
flight.seekg(0);
cout<<"Search results:\n";
while(flight)
{
flight.read((char*)& f, sizeof(Flight));
if((f.check(leave,destination))&&(f.get_time_code()==depart_time))
{
f.short_display();
found=1;
}
}
if(found)
{
cout<<"Enter flight code to get more information:\n";
cin>>a1;
return a1;
}
else
return 0;
}
int search_hotels()
{
Hotel h;
int a2;
int found=0;
while(hotel)
{
hotel.read((char*)& h, sizeof(Hotel));
if(destination==h.get_location())
{
found=1;
h.short_display();
}
}
if(found)
{
cout<<"Enter hotel code to get more information:\n";
cin>>a2;
return a2;
}
else
return 0;
}
int search_rails()
{
Rail r;
int a3;
int found=0;
rail.seekg(0);
while(rail)
{
rail.read((char*)& r,sizeof(Rail));
if(r.check(leave,destination))
{
found=1;
r.short_display();
}
}
if(found)
{
cout<<"Enter train code to get more information:\n";
cin>>a3;
return a3;
}
else
return 0;
}

int search_buses()
{
Bus b;
int a4;
int found=0;
bus.seekg(0);
while(bus)
{
bus.read((char*)& b,sizeof(Bus));
if(b.check(leave,destination))
{
found=1;
b.short_display();
}
}
if(found)
{
cout<<"Enter bus code to get more information:\n";
cin>>a4;
return a4;
}
else
return 0;
}
int search_holiday()
{
Holiday h;
int a5;
int found=0;
holiday.seekg(0);
while(holiday)
{
holiday.read((char*)& h,sizeof(Holiday));
if(h.get_destination()==destination)
{
found=1;
h.short_display();
}
}
if(found)
{
cout<<"Enter holiday code to get more information:\n"
cin>>a5;
return a5;
}
else
return 0;
}
void refresh()
{
leave=0;
destination=0;
date.refresh();
depart_time=0;
adults=0;
children=0;
infants=0;
j=0;
c=0;
duration=0;
}
void book(int code, int choice)
{
int check=0;
char ch;
Record r;
Booked b;
cout<<"\nYou have selected the following ";
switch(choice)
{
case 1: Flight f;
flight.seekg(0,ios::beg);
while(flight)
{
flight.read((char*)& f,sizeof(f));
if(code==f.get_code())
break;
}
cout<<"flight:";
f.display();
cout<<"\nChecking availability\n";
f.check_availability(r);
if(r.get_left()!=0)
{
cout<<"Seats available\n";
check=1;
}
else
cout<<"Sorry! Seats unavailable\n";
break;
case 2: Hotel h;
hotel.seekg(0,ios::beg);
while(hotel)
{
hotel.read((char*)& h,sizeof(h));
if(code==h.get_code())
break;
}
cout<<"hotel:";
h.display();
cout<<"\nChecking availability\n";
h.check_availability(r);
if(r.get_left()!=0)
{
cout<<"Seats available\n";
check=1;
}
else
cout<<"Sorry! Seats unavailable\n";
break;
case 3: Rail rl;
rail.seekg(0,ios::beg);
while(rail)
{
rail.read((char*)& f,sizeof(rl));
if(code==rl.get_code())
break;
}
cout<<"flight:";
rl.display();
cout<<"\nChecking availability\n";
rl.check_availability(r);
if(r.get_left()!=0)
{
cout<<"Seats available\n";
check=1;
}
else
cout<<"Sorry! Seats unavailable\n";
break;
case 4: Bus b;
bus.seekg(0,ios::beg);
while(bus)
{
bus.read((char*)& b,sizeof(b));
if(code==b.get_code())
break;
}
cout<<"bus:";
b.display();
cout<<"\nChecking availability\n";
b.check_availability(r);
if(r.get_left()!=0)
{
cout<<"Seats available\n";
check=1;
}
else
cout<<"Sorry! Seats unavailable\n";
break;
case 5: Holiday h;
holiday.seekg(0,ios::beg);
while(holiday)
{
holiday.read((char*)& h,sizeof(h));
if(code==h.get_code())
break;
}
cout<<"holiday:";
h.display();
cout<<"\nChecking availability\n";
h.check_availability(r);
if(r.get_left()!=0)
{
cout<<"Seats available\n";
check=1;
}
else
cout<<"Sorry! Seats unavailable\n";
break;
}
if(check)
{
cout<<"Confirm this booking?(y/n):";
cin>>ch;
if((ch=='y')||(ch=='Y))
check=b.confirm(code,choice);
if(check)
{
r.update();
cout<<"\nYour booking has been confirmed.\nYpur reference number is:"<<b.get_reference();
book.write((char*)& b,sizf(b));
write_record.seekp(read_record.tellg()-sizeof(r),ios::beg);
write_record.write((char*)& r,sizeof(r));
}
else
cout<<"Unable to confirm booking,";
}
}
void check_status()
{
cout<<"Reference number:";
int n;
cin>>n;
Booked b;
booking.seekg(0,ios::beg);
while(booking)
{
booking.read((char*)& b,sizeof(b));
if(n==b.get_reference())
{
b.display();
break;
}
else
n=0;
}
if(!n)
cout<<"Invalid reference number.\nPlease make sure that the number you have entered is correct.";
}
void login()
{
ofstream get_flight("Flights.dat",ios::binary,ios::app);
ofstream get_hotel("Hotel.dat",ios::binary,ios::app);
ofstream get_rail("Rails.dat",ios::binary,ios::app);
ofstream get_bus("Bus.dat",ios::binary,ios::app);
ofstream get_holiday("Holiday.dat",ios::binary,ios::app);
ofstream get_place("Places.dat",ios::binary,ios::app);
ifstream read_pass("Password.dat",ios::binary);
int choice;
char pass[20];
Password p;
read_pass.read((char*)& p,sizeof(p));
cout<<"Password:";
gets(pass);
if(p.compare_pass(pass))
{
do
{
login_menu();
cin>>choice;
switch(choice)
{
case 1: Flight f;
f.assign();
get_flight.write((char*)& f,sizeof(f));
break;
case 2: Hotel h;
h.assign();
get_hotel.write((char*)& h,sizeof(h));
break;
case 3: Rail r;
r.assign();
get_rail.write((char*)& r,sizeof(r));
break;
case 4: Bus b;
b.assign();
get_bus.write((char*)& b,sizeof(b));
break;
case 5: Holiday h;
h.assign();
get_holiday.write((char*)& h,sizeof(h));
break;
case 6: Place p;
p.assign();
get_place.write((chr*)& p,sizeof(p));
break;
case 7: cout<<"Password:\n";
p.change_pass();
write_pass.write((char*)& p,sizeof(p));
break;
case 8: cout<<"\nExiting...\n";
break;
default:cout<<"\nInvalid option.\nAccess denied.";
}
}while(choice!=7);
}
else
cout<<"Invalid password!!\nAccess denied...";
}

void main()
{
cout<<"Welcome to KHK Travel Agency"<<endl;
int choice;
do{
menu();
cout<<"Enter your option:"<<endl;
cin>>choice;
switch(choice)
{
case 1: cout<<"Booking Flights\n";
read_info(choice);
if(c=search_flight())
{
book(c,choice);
}
else
{
cout<<"Sorry.There does not exist any flight between the destinations you entered.\n";
}
refresh();
break;
case 2: cout<<"Booking Hotels\n";
read_info(choice);
if(c=search_hotels())
{
book(c,choice);
}
else
{
cout<<"Sorry.There does not exist any hotel under our network in the place specified by you.\n";
}
refresh();
break;
case 3: cout<<"Online Railway Reservation\n";
read_info(choice);
if(c=search_rails())
{
book(c,choice);
}
else
{
cout<<"Sorry.No train routes exist between the stations you entered.\n";
}
refresh();
break;
case 4: cout<<"Online Bus Seats Booking\n";
read_info(choice);
if(c=search_buses())
{
book(c,choice);
}
else
{
cout<<"Sorry.No bus routes exist between the places you entered.\n";
}
refresh();
break;
case 5: cout<<"Planning Holidays\n";
holiday_info();
if(c=search_holidays())
{
book(c,choice);
}
else
{
cout<<"Sorry.Our travel agency does not arrange holidays in the city you entered.\n";
}
refresh();
break;
case 6: check_status();
break;
case 7: login();
break;
case 8: cout<<"Thank You for using KHK Travel Agency.\nPlease visit again.\n";
break;
default: cout<<"Invalid input!!\nPlease enter your option again.\n";
}
}while(choice!=7);
}
Posted
Updated 18-Jan-10 0:55am
v5
Rate this:
Please Sign up or sign in to vote.

Solution 2

I have several things to mention.

The code you posted is not well formatted. Select the code in your post and click on "code block". Add indentation to it to show the structure and make it more readable. I also think it is overly long for a post. Something shorter & better formatted would be easier/more likely for people to read & help you with. Yes, you are saying, "but that's how long my code is." Well, you could try to temporarily remove parts of your code to get something smaller that exhibits the problem. This could even help you find the problem yourself.

Next,
you wrote:
while compiling i got an exception 13 error

I was confident that this is inaccurate. Since you posted the error message I am not so confident. When building a program there is: pre-processing, compile, and link time. After this there is run time. I believe that your General Protection Fault (exception 13) is at run-time. It is important to have the process clear in your head both for communication and for figuring things out yourself. ( A GPF at compile time is a potential - I have seen the equivalent. )

The compiler you are using is from somewhere around 1990 to 1995. It was good then. However, changes were made to the C++ language in the 1990s that had a profound affect on the language. The standard for the language was officially released in 1998. Your compiler will not handle standard C++. The dialect it does accept is not appropriate for a standards compliaint compiler like (hopefully) most of use are using. It may also not be fully compatible with Windows XP.

I have recently dealt with a client who was trying to put Turbo C version 3.0 on Windows XP to support a very legacy C (not C++) DOS project. It turned out that the (DOS legal) names of some of the source code files were triggering some error in Turbo C under XP, though there had been no problem when running under earlier versions of Windows. You may be experiencing something similar. If you really, really have to use this compiler, you might try digging out a Windows 95 or 98 machine to go with it. If you are learning C++ for the future, you should move on to a modern compiler. Microsoft has an express edition of their compiler that can be downloaded for free.

Now, if you were using a reasonably modern compiler on Windows and this occurred at runtime, you would be getting an option to start the debugger. This would at least tell you where your code died. This could be a starting point to figuring out your problem.

Finally, in glancing over your code I can see a number of issues. You are going to need to work on it to find them all. I will only point out three here.

1) You have in your code:
if((day>0)||(day<32)||(month>0)||(month<13)||(year>2009)||(year<2014))

This test will never fail. What you wrote was not what you intended and you will need to think about it and fix it. It is not, however, the cause of your exception 13.

2) You are using both gets() and std::cin for input. They are likely to interfere with each other. Choose one and stick to it.

3) You are doing input into char arrays at various places. If the input is longer than you have allowed for, Bad Things can happen - including a GPF. This or something like it could very well be your problem. Consider using std::string (with std::cin) instead. Note: Your current compiler does not have this.
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

Compiler errors are full of useful information, for instance, they indicate the line of the source code wherein the error occurs.
Please post just the relevant code and the full compiler error message.
:)
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

wrote:
#include<iostream.h>


This is not valid C++. If your teacher thinks it is, find a new teacher.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100