I'm in my last week in High School and my last program has seemed to have been shot. My teacher blames it on the computers and says that my program should run, but I have an error opening my files.
This is my header:
---------------------------------------------------------------------------
#include<iostream.h>
#include<string.h>
#include<fstream.h>
#include<IO.h>
struct carinfo
{
char vehicle[50],manu[50],model[50];
long year,cmilage,vin;
float drentprice,mrentprice;
};
int numhold,x;
carinfo car[50];
void enterinfo();
void output();
void findtype();
void dayrent();
void open();
void sort();
void adddel();
void years();
void main()
{...
}
-------------------------------------------------------------------------
The program works fine until my open function when it displays 00_Done Checking about 30 times, and two lines in there contain randon junk (letters, numbers, music notes, etc.). Then the Just-In-Time debugger comes up and tells me there is something wrong. Visual Basic told me the error is where I bolded it below. I took it home to my free software and said that there was a parse error in that line. Here is my open function:
--------------------------------------------------------------------------
void open()
{ ifstream infile;
infile.open("car.dat", ios::in);
int x;
x=1;
do
{
infile.get(car[x].vehicle, 49);
cout<<car[x].vehicle;
infile.ignore (80,'\n');
infile.get(car[x].manu, 49);
infile.ignore(80,'\n');
cout<<car[x].manu;
infile.get(car[x].model, 49);
infile.ignore(80,'\n');
cout<<car[x].model;
infile.ignore(80,'\n');
infile >> car[x].year;
cout<<car[x].year;
infile >> car[x].cmilage;
cout<<car[x].cmilage;
infile >> car[x].drentprice;
cout<<"Done Checking OPEN.\n";
infile >> car[x].mrentprice;
infile >> car[x].vin;
x=x+1;
}
while(!infile.eof());
numhold=x-1;
infile.close();
}
--------------------------------------------------------------------------
I'm out of ideas, and I'm almost falling into my last resort of making them all strings. If someone knows anything it would be apprecaited. My whole program is below if you must see it.
I'm not on my schools computer right now, so I can't give you in detail what might have flown up onto the screen, and my free software at home is a piece of junk.
--------------------------------------------------------------------------
Whole Program:
#include<iostream.h>
#include<string.h>
#include<fstream.h>
#include<IO.h>
struct carinfo
{
char vehicle[50],manu[50],model[50];
long year,cmilage,vin;
float drentprice,mrentprice;
};
int numhold,x;
carinfo car[50];
void enterinfo();
void output();
void findtype();
void dayrent();
void open();
void sort();
void adddel();
void years();
void main()
{
int choice;
numhold=0;
cout<<"This program keeps vehicle inventory.\n\n";
do
{
cout<<"\n\n\n\n\n";
cout<<"Menu\n";
cout<<"----\n";
cout<<"(1) Enter Vehicles (Erase All Previous Data)\n";
cout<<"(2) Enter More Vehicles\n";
cout<<"(3) Print Vehicles (ABC)\n";
cout<<"(4) Find Type Of Vehicle (car/truck)\n";
cout<<"(5) Show By Expense on Day Rental\n";
cout<<"(6) Delete by VIN\n";
cout<<"(7) Search for a vehicle by year.\n";
cout<<"(8) Exit\n";
cout<<"What is your choice:";
cin>>choice;
switch(choice)
{case 1:
enterinfo();
break;
case 2:
open();
enterinfo();
break;
case 3:
open();
output();
break;
case 4:
open();
sort();
findtype();
break;
case 5:
open();
sort();
dayrent();
break;
case 6:
open();
sort();
adddel();
break;
case 7:
open();
years();
break;
}
}while(choice!=8);
}
void enterinfo()
{
int input,numtimes;
cout<<"How Many Cars Do You Plan On Entering:";
cin>>numtimes;
ofstream outfile;
outfile.open("car.dat",ios::out);
if (outfile)
{
cout<<"Please fill in the information by inputing the indicated number.\n";
for (x=1;x<=numtimes;x++)
{
cin.ignore (80,'\n');
cout<<"Car #"<<x+numhold<<"\n";
cin.ignore (80,'\n');
cout<<"Car (1) or Truck (2):";
cin>>input;
if (input==1)
{
strcpy(car[x+numhold].vehicle,"Car");
outfile<<car[x+numhold].vehicle<<'\n';
cout<<car[x+numhold].vehicle;
}
else
{
strcpy(car[x+numhold].vehicle,"Truck");
outfile<<car[x+numhold].vehicle<<'\n';
cout<<car[x+numhold].vehicle;
}
cin.ignore (80,'\n');
cout<<"Who was the Manufacture?\n";
cout<<"(1) Ford (2) GM (3) Chrysler (4) Toyota (5) Honda:";
cin>>input;
if (input==1)
{
strcpy(car[x+numhold].manu,"Ford");
outfile<<car[x+numhold].manu<<'\n';
cout<<car[x+numhold].manu;
}
else if (input==2)
{
strcpy(car[x+numhold].manu,"GM");
outfile<<car[x+numhold].manu<<'\n';
cout<<car[x+numhold].manu;
}
else if (input==3)
{
strcpy(car[x+numhold].manu,"Chrysler");
outfile<<car[x+numhold].manu<<'\n';
cout<<car[x+numhold].manu;
}
else if (input==4)
{
strcpy(car[x+numhold].manu,"Toyota");
outfile<<car[x+numhold].manu<<'\n';
cout<<car[x+numhold].manu;
}
else
{
strcpy(car[x+numhold].manu,"Honda");
outfile<<car[x+numhold].manu<<'\n';
cout<<car[x+numhold].manu;
}
cin.ignore (80,'\n');
cout<<"\nWhat is the body model:\n";
cout<<"(1) Pickup (2) Sedan (3) Station Wagon (4) Van (5) SUV:";
cin>>input;
if (input==1)
{
strcpy(car[x+numhold].model,"Pick Up");
outfile<<car[x+numhold].model<<'\n';
cout<<car[x+numhold].model;
}
else if (input==2)
{
strcpy(car[x+numhold].model,"Sedan");
outfile<<car[x+numhold].model<<'\n';
cout<<car[x+numhold].model;
}
else if (input==3)
{
strcpy(car[x+numhold].model,"Station Wagon");
outfile<<car[x+numhold].model<<'\n';
cout<<car[x+numhold].model;
}
else if (input==4)
{
strcpy(car[x+numhold].model,"Van");
outfile<<car[x+numhold].model<<'\n';
cout<<car[x+numhold].model;
}
else
{
strcpy(car[x+numhold].model,"SUV");
outfile<<car[x+numhold].model<<'\n';
cout<<car[x+numhold].model;
}
cin.ignore (80,'\n');
cout<<"\n\n";
cout<<"What is the year (####):";
cin>>car[x+numhold].year;
cout<<car[x+numhold].year;
outfile<<car[x+numhold].year<<'\n';
cout<<"\n";
cout<<"What is the current milage:";
cin>>car[x+numhold].cmilage;
cout<<car[x+numhold].cmilage;
cout<<"Done Checking INPUT";
outfile<<car[x+numhold].cmilage<<'\n';
cout<<"\n";
cout<<"What is the daily rental price: $";
cin>>car[x+numhold].drentprice;
outfile<<car[x+numhold].drentprice<<'\n';
cout<<car[x+numhold].drentprice;
cout<<"\n";
cout<<"What is the milage rental price: $";
cin>>car[x+numhold].mrentprice;
outfile<<car[x+numhold].mrentprice<<'\n';
cout<<"\n";
cout<<"What is the VIN number:";
cin>>car[x+numhold].vin;
outfile<<car[x+numhold].vin<<'\n';
cout<<"\n\n\n\n\n\n\n";
} numhold+=numtimes;
}
else
{
cout<<"File not open.\n";
}
outfile.close();
//numhold is a global varible keeping track of the student count.
}
void output()
{
cout<<"\n\n";
cout<<"Type |Manufacturer\n";
cout<<"Model | Year \n";
cout<<"----------------------------------------------------------\n";
for (x=1;x<=numhold;x++)
{
cout<<x<<"\n";
cout<<car[x].vehicle<<"--"<<car[x].manu<<" \n";
cout<<""<<car[x].model<<"--"<<car[x].year<<" \n\n";
cout<<"Current Mileage: "<<car[x].cmilage<<"\n";
cout<<"Daily Rent Price: $"<<car[x].drentprice<<"\n";
cout<<"Milage Rent Price: $"<<car[x].mrentprice<<"\n";
cout<<"VIN: "<<car[x].vin<<"\n";
cout<<"---------------------------------\n\n";
}
cout<<"\n\n\n\n";
}
continued on the next thread due to size....