[build error] [project1] error 1

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

#include <iostream>

#include "cashier.h"
#include "invmenu.h"
#include "bookinfo.h"
#include "reports.h"

extern const int ROWS=20;

extern char bookTitle[ROWS][51],
isbn[ROWS][14],
author[ROWS][31],
publisher[ROWS][31],
dateAdded[ROWS][11];//MM-DD-YYYY

extern int qtyOnHand[(ROWS+1)];

extern double wholesale[(ROWS+1)],
retail[(ROWS+1)];

#endif


/************************** Inventory.h **************************************/
#ifndef INVMENU_H
#define INVMENU_H

#include<iostream>
#include<iomanip>
#include<fstream>
#include "header.h"

void invMenu();
void lookUpBook();
void addBook();
void editBook();
void deleteBook();

#endif


/******************************** 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;
    }
   
your version is missing the "}" for the void but mine has it. i will re-post whole thing with indents.
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

#include <iostream>

#include "cashier.h"
#include "invmenu.h"
#include "bookinfo.h"
#include "reports.h"

extern const int ROWS=20;

extern char bookTitle[ROWS][51],
isbn[ROWS][14],
author[ROWS][31],
publisher[ROWS][31],
dateAdded[ROWS][11];//MM-DD-YYYY

extern int qtyOnHand[(ROWS+1)];

extern double wholesale[(ROWS+1)],
retail[(ROWS+1)];

#endif


/************************** Inventory.h **************************************/
#ifndef INVMENU_H
#define INVMENU_H

#include<iostream>
#include<iomanip>
#include<fstream>
#include "header.h"

void invMenu();
void lookUpBook();
void addBook();
void editBook();
void deleteBook();

#endif


/******************************** 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;
}
wtf its not recognizing my indents
Use code tags and it will.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/******************************** 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;
}
What do the errors say?
What are the errors? Why is it all commented out, it just makes it harder to read.
i have commented out and now getting error of multiple definitions of ROWS.
now i have an issue with my global variables. do i #include "header.h" in function.cpp? have made header.h properly
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#ifndef HEADER_H
#define HEADER_H

   #include <iostream>

   #include "cashier.h"
   #include "invmenu.h"
   #include "bookinfo.h"
   #include "reports.h"
   
   extern const int ROWS=20;

   extern char bookTitle[ROWS][51],
        isbn[ROWS][14],
        author[ROWS][31],
        publisher[ROWS][31],
        dateAdded[ROWS][11];//MM-DD-YYYY
        
   extern int qtyOnHand[(ROWS+1)];
   
   extern double wholesale[(ROWS+1)], 
                 retail[(ROWS+1)];

#endif

i have reposted cleaner copy.
"cannot compile"
On line 11: remove extern. constants can't be extern
thanks i did it but still error
What are the exact words of the(se) error(s). Or should be still guess...
[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.
if that's the only output of the compiler/linker -> get another one.

Where are all those globals (shudder) defined? (Hint: it must be in a *.cpp)
nice comment coder. i have been at it for awhile.

@coder777

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.
Last edited on
figured it out
const unsigned int ROWS_2D = 20;
i knew it was calling it more than once. know i know the "unsigned" prevents a multiple decloration.
:):):):):):):):) HAPPY!!!!!! :):):):):):):):)
*>cheers<*
Topic archived. No new replies allowed.