i cannot compile this code.
any help would be much appreciated.
i think the problem is in the add book function.
more specifically inFile
also i cant get cin to work eather
/******************************* main Header file *****************************/
#ifndef HEADER_H
#define HEADER_H
/******************************** add book ************************************/
void addBook()
{
int index=-1;
for(int count=0 ; count<(ROWS-1) ; count++)
{
if(!bookTitle[count][0])
{
index=count;
break;
}
}
if(index==-1)
{
cout<<"\a\t No more bookes may be added to the inventory"<<endl;
return;
}
/******************************* cin *************************************/
/*
cout<<"\t Please enter the book title: ";
cin.getline(bookTitle[index],50);
cout<<endl;
cout<<"\t Please enter the ISBN number: ";
cin.getline(isbn[index],13);
cout<<endl;
cout<<"\t Please enter the authors Name: ";
cin.getline(author[index],30);
cout<<endl;
cout<<"\t Please enter the publisher name: ";
cin.getline(publisher[index],30);
cout<<endl;
cout<<"\t Please enter the date the book was added in the form MM-DD-YYYY: ";
cin.getline(dateAdded[index],10);
cout<<endl;
cout<<"\t Please enter the quantity: ";
cin>>qtyOnHand[index];
cout<<endl;
cout<<"\t Please enter the wholesale cost: ";
cin>>wholesale[index];
cout<<endl;
cout<<"\t Please enter the retail price: ";
cin>>retail[index];
cout<<endl;
/****************************** inFile ***********************************/
ifstream inFile("input_inv_menu.txt");
if (!inFile)
{
cout<<"Could not open file";
return;
}
cout<<"\t Please enter the book title: ";
inFile.getline(bookTitle[index],50);
cout<<endl;
cout<<"\t Please enter the ISBN number: ";
inFile.getline(isbn[index],13);
cout<<endl;
cout<<"\t Please enter the authors Name: ";
inFile.getline(author[index],30);
cout<<endl;
cout<<"\t Please enter the publisher name: ";
inFile.getline(publisher[index],30);
cout<<endl;
cout<<"\t Please enter the date the book was added in the form MM-DD-YYYY: ";
inFile.getline(dateAdded[index],10);
cout<<endl;
cout<<"\t Please enter the quantity: ";
inFile>>qtyOnHand[index];
cout<<endl;
cout<<"\t Please enter the wholesale cost: ";
inFile>>wholesale[index];
cout<<endl;
cout<<"\t Please enter the retail price: ";
inFile>>retail[index];
cout<<endl;
/*************************** end input ***********************************/
return;
}
Did you ever notice how so much of the code you read in books and on the wbe indents lines? It's for a good reason. I have indented some of your code. See if you can spot the problem now. Take a look at the way each { is lined up with a }.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/******************************** add book ************************************/
void addBook()
{
int index=-1;
for(int count=0 ; count<(ROWS-1) ; count++)
{
if(!bookTitle[count][0])
{
index=count;
break;
}
}
if(index==-1)
{
cout<<"\a\t No more bookes may be added to the inventory"<<endl;
return;
}
i cannot compile this code.
any help would be much appreciated.
i think the problem is in the add book function.
more specifically inFile
also i cant get cin to work eather
/******************************* main Header file *****************************/
#ifndef HEADER_H
#define HEADER_H
/******************************** add book ************************************/
void addBook()
{
int index=-1;
for(int count=0 ; count<(ROWS-1) ; count++)
{
if(!bookTitle[count][0])
{
index=count;
break;
}
}
if(index==-1)
{
cout<<"\a\t No more bookes may be added to the inventory"<<endl;
return;
}
/******************************* cin *************************************/
/*
cout<<"\t Please enter the book title: ";
cin.getline(bookTitle[index],50);
cout<<endl;
cout<<"\t Please enter the ISBN number: ";
cin.getline(isbn[index],13);
cout<<endl;
cout<<"\t Please enter the authors Name: ";
cin.getline(author[index],30);
cout<<endl;
cout<<"\t Please enter the publisher name: ";
cin.getline(publisher[index],30);
cout<<endl;
cout<<"\t Please enter the date the book was added in the form MM-DD-YYYY: ";
cin.getline(dateAdded[index],10);
cout<<endl;
cout<<"\t Please enter the quantity: ";
cin>>qtyOnHand[index];
cout<<endl;
cout<<"\t Please enter the wholesale cost: ";
cin>>wholesale[index];
cout<<endl;
cout<<"\t Please enter the retail price: ";
cin>>retail[index];
cout<<endl;
/****************************** inFile ***********************************/
ifstream inFile("input_inv_menu.txt");
if (!inFile)
{
cout<<"Could not open file";
return;
}
cout<<"\t Please enter the book title: ";
inFile.getline(bookTitle[index],50);
cout<<endl;
cout<<"\t Please enter the ISBN number: ";
inFile.getline(isbn[index],13);
cout<<endl;
cout<<"\t Please enter the authors Name: ";
inFile.getline(author[index],30);
cout<<endl;
cout<<"\t Please enter the publisher name: ";
inFile.getline(publisher[index],30);
cout<<endl;
cout<<"\t Please enter the date the book was added in the form MM-DD-YYYY: ";
inFile.getline(dateAdded[index],10);
cout<<endl;
cout<<"\t Please enter the quantity: ";
inFile>>qtyOnHand[index];
cout<<endl;
cout<<"\t Please enter the wholesale cost: ";
inFile>>wholesale[index];
cout<<endl;
cout<<"\t Please enter the retail price: ";
inFile>>retail[index];
cout<<endl;
/*************************** end input ***********************************/
return;
}
/******************************** add book ************************************/
void addBook()
{/*
int index=-1;
for(int count=0 ; count<(ROWS-1) ; count++)
{
if(!bookTitle[count][0])
{
index=count;
break;
}
}
if(index==-1)
{
cout<<"\a\t No more bookes may be added to the inventory"<<endl;
return;
}
/******************************* cin *************************************/
/*
cout<<"\t Please enter the book title: ";
cin.getline(bookTitle[index],50);
cout<<endl;
cout<<"\t Please enter the ISBN number: ";
cin.getline(isbn[index],13);
cout<<endl;
cout<<"\t Please enter the authors Name: ";
cin.getline(author[index],30);
cout<<endl;
cout<<"\t Please enter the publisher name: ";
cin.getline(publisher[index],30);
cout<<endl;
cout<<"\t Please enter the date the book was added in the form MM-DD-YYYY: ";
cin.getline(dateAdded[index],10);
cout<<endl;
cout<<"\t Please enter the quantity: ";
cin>>qtyOnHand[index];
cout<<endl;
cout<<"\t Please enter the wholesale cost: ";
cin>>wholesale[index];
cout<<endl;
cout<<"\t Please enter the retail price: ";
cin>>retail[index];
cout<<endl;
/****************************** inFile ***********************************/
/*
if (!inFile)
{
cout<<"Could not open file";
return;
}
cout<<"\t Please enter the book title: ";
inFile.getline(bookTitle[index],50);
cout<<endl;
cout<<"\t Please enter the ISBN number: ";
inFile.getline(isbn[index],13);
cout<<endl;
cout<<"\t Please enter the authors Name: ";
inFile.getline(author[index],30);
cout<<endl;
cout<<"\t Please enter the publisher name: ";
inFile.getline(publisher[index],30);
cout<<endl;
cout<<"\t Please enter the date the book was added in the form MM-DD-YYYY: ";
inFile.getline(dateAdded[index],10);
cout<<endl;
cout<<"\t Please enter the quantity: ";
inFile>>qtyOnHand[index];
cout<<endl;
cout<<"\t Please enter the wholesale cost: ";
inFile>>wholesale[index];
cout<<endl;
cout<<"\t Please enter the retail price: ";
inFile>>retail[index];
cout<<endl;
inFile.close();
*/
/*************************** end input ***********************************/
return;
}
[build error] [project1] error 1.
it has to do with inFile. probably how i am reading into a two dimensional array. i am trying to read mutiple words into 2D array.
On line 11: remove extern. constants can't be extern
It si a wrong statement. Constants as any other variables may be declared with the storage-class specifier extern.
The problem of the code is not that the declaration of the constant has the storage-class specifier extern. The problem is that one entity that is the constant defined several times.
figured it out constunsignedint ROWS_2D = 20;
i knew it was calling it more than once. know i know the "unsigned" prevents a multiple decloration.
:):):):):):):):) HAPPY!!!!!! :):):):):):):):)
*>cheers<*