Arrays to read inventory file

This is what i have so far.I need to print a report and the data must be read with arrays.
data must ptinted similar to:

Month: March

Item Begin qty units sold ending qty %sold
- - - - -***- - - - -***- - - - - ***- - - - -_ *******- - -
Rope 132 lines 24 108 18.18
the stars would be the setw spaces in between.

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <fstream>


using namespace std;

char month[7];
char Item[13];
int Begin_qty[4];
char Begin_descrip[10];
int Units_sold[3];

void Datain(ifstream &inData, char month[7], char Item[13], int Begin_qty[4], char Begin_descrip[10], int Units_sold[3]);

void Dataout(ofstream &outData,char month[7], char Item[13], int Begin_qty[4], char Begin_descrip[10], int Units_sold[3]);


int main ()

{
ifstream inData;
char month[7];
char Item[13];
int& Begin_qty[4];
char Begin_descrip[10];
int& Units_sold[3];
ofstream outData;

char file[15];
cout<< "Please enter Filename :";
cin>>file;
inData.open(file);

char ofile[15];
cout<<"Please enter Filename to save :";
cin>>ofile;
outData.open (ofile);
system("cls");

while (!inData.fail())
{
Datain(inData, month,Item, Begin_qty, Begin_descrip, Units_sold);
if(!inData.fail())
Dataout(outData, month,Item,Begin_qty,Begin_descrip, Units_sold);
}

return 0;
}

void Datain(ifstream &inData, char month[],char Item[], int Begin_qty[], char Begin_descrip[], int Units_sold[])
{
inData>>month>>Item>>Begin_qty>>Units_sold;

}


void Dataout(ofstream &outData,char month[],char Item[], int Begin_qty[], char Begin_descrip[], int Units_sold[])
{
outData<<"Month :"<<month<<"\n";
outData<< "ITEM"<< setw(5)<<"BEGIN QTY"<<setw(5)<<"UNITS SOLD"<<setw(5)<<"ENDING QTY"<<setw(5)<<"SOLD/n";

}
Can someone please help?
I'm recieving this error cpp(56) : error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'int []' (or there is no acceptable conversion)
Last edited on
ok i fixed that problem but my data won't print in the outfile? what should i do.
What does your code look like now?
Lots of errors in the original.
Last edited on
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <fstream>


using namespace std;

char month[10];
char Item[13];
int Begin_qty[4];
char Begin_descrip[10];
int Units_sold[3];

void Datain(ifstream &inData, char month[10], char Item[13], double Begin_qty[4], char Begin_descrip[10], double Units_sold[3]);

void Dataout(ofstream &outData,char month[10], char Item[13], double Begin_qty[4], char Begin_descrip[10], double Units_sold[3]);


int main ()

{
ifstream inData;
char month[10];
char Item[13];
double Begin_qty[4];
char Begin_descrip[10];
double Units_sold[3];
ofstream outData;

char file[15];
cout<< "Please enter Filename :";
cin>>file;
inData.open(file);

char ofile[15];
cout<<"Please enter Filename to save :";
cin>>ofile;
outData.open (ofile);
system("cls");

while (!inData.fail())
{
Datain(inData, month,Item, Begin_qty, Begin_descrip, Units_sold);
if(!inData.fail())
Dataout(outData, month,Item,Begin_qty,Begin_descrip, Units_sold);
}

return 0;
}

void Datain(ifstream &inData, char month[],char Item[], double Begin_qty[], char Begin_descrip[], double Units_sold[])
{
inData>>month>>Item>>Begin_qty[4]>>Units_sold[3];

}


void Dataout(ofstream &outData,char month[],char Item[], double Begin_qty[], char Begin_descrip[], double Units_sold[])
{
double sold,endqty;
endqty=Begin_qty-Units_sold;
sold=Units_sold%Begin_qty;

outData<<"Month :"<<month<<"\n\n";
outData<< "ITEM"<< setw(5)<<"BEGIN QTY"<<setw(5)<<"UNITS SOLD"<<setw(5)<<"ENDING QTY"<<setw(5)<<"SOLD\n";
out data<<Item<<setw(5)<<Begin_qty<<setw(5)<<Begin_descrip<<setw(5)<<Units_sold<<setw(5<<endqty<<setw(5)<<sold;

}
I need help getting this program together. i keep getting these errors.
1>------ Build started: Project: Lab 7, Configuration: Debug Win32 ------
error C2440: '=' : cannot convert from 'double []' to 'double'
1> There is no context in which this conversion is possible
error C2440: '=' : cannot convert from 'double []' to 'double'
1> There is no context in which this conversion is possible
error C2297: '<<' : illegal, right operand has type 'double'
error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'int'
: see declaration of 'std::operator <<'
: error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const std::_Smanip<_Arg> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'int'
: see declaration of 'std::operator <<'
: error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const std::_Fillobj<_Elem> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'int'
: see declaration of 'std::operator <<'
: error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'int'
1> 'std::operator <<'
: error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const unsigned char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'int'
and so on.....
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <fstream>


using namespace std;

char month[10];
char Item[13];
int Begin_qty[4];
char Begin_descrip[10];
int Units_sold[3];

void Datain(ifstream &inData, char month[10], char Item[13], double Begin_qty[4], char Begin_descrip[10], double Units_sold[3]);

void Dataout(ofstream &outData,char month[10], char Item[13], double Begin_qty[4], char Begin_descrip[10], double Units_sold[3]);


int main ()

{
ifstream inData;
char month[10];
char Item[13];
double Begin_qty[4];
char Begin_descrip[10];
double Units_sold[3];
ofstream outData;

char file[15];
cout<< "Please enter Filename :";
cin>>file;
inData.open(file);

char ofile[15];
cout<<"Please enter Filename to save :";
cin>>ofile;
outData.open (ofile);
system("cls");

while (!inData.fail())
{
Datain(inData, month,Item, Begin_qty, Begin_descrip, Units_sold);
if(!inData.fail())
Dataout(outData, month,Item,Begin_qty,Begin_descrip, Units_sold);
}

return 0;
}

void Datain(ifstream &inData, char month[],char Item[], double Begin_qty[], char Begin_descrip[], double Units_sold[])
{
inData>>month>>Item>>Begin_qty[4]>>Units_sold[3];

}


void Dataout(ofstream &outData,char month[],char Item[], double Begin_qty[], char Begin_descrip[], double Units_sold[])
{
double sold,endqty,begin,units;
begin=Begin_qty;
units=Units_sold;
endqty=begin-units;
sold=units/begin;

outData<<"Month :"<<month<<"\n\n";
outData<< "ITEM"<< setw(5)<<"BEGIN QTY"<<setw(5)<<"UNITS SOLD"<<setw(5)<<"ENDING QTY"<<setw(5)<<"SOLD\n";
outData<<Item<<setw(5)<<Begin_qty<<setw(5)<<Begin_descrip<<setw(5)<<Units_sold<<setw(5<<endqty<<setw(5)<<sold;

}
I would be very thankful if i could get help before 12:00 am.
Scanning over the errors, it seems like in some cases you are trying to assign an array of doubles to a single double (which you cannot do) and in other places you are providing illegal types...perhaps double[] is not acceptable?

Please use [code][/code] tags too, it makes the code more readable to preserves indentation.
so how can i give the array a temp value?
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
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <fstream>

using namespace std;

/*   Don't need these Globals ///////////////////
char month[10];
char Item[13];
int Begin_qty[4];
char Begin_descrip[10];
int Units_sold[3];////////////////////////////*/

void Datain(ifstream &inData, char month[10], char Item[13], double Begin_qty[4], char Begin_descrip[10], double Units_sold[3]);

void Dataout(ofstream &outData,char month[10], char Item[13], double Begin_qty[4], char Begin_descrip[10], double Units_sold[3]);


int main ()

{

    ifstream inData;
    char month[10];
    char Item[13];
    double Begin_qty[4]; //WHY IS THIS AN ARRAY
    char Begin_descrip[10];
    double Units_sold[3];  //WHY IS THIS AN ARRAY
    ofstream outData;

    char file[15];
    cout<< "Please enter Filename :";
    cin>>file;
    inData.open(file);

    char ofile[15];
    cout<<"Please enter Filename to save :";
    cin>>ofile;
    outData.open (ofile);
    system("cls");

    while (!inData.fail())
    {
        Datain(inData, month,Item, Begin_qty, Begin_descrip, Units_sold);
        if(!inData.fail())
        Dataout(outData, month,Item,Begin_qty,Begin_descrip, Units_sold);
    }

    return 0;
}


// Begin_qty and Units_sold  should not be defined as arrays
//Once Begin_qty and Units_sold have been changed from arrays to normal variable - and they should
// be passed by reference
void Datain(ifstream &inData, char month[],char Item[], double Begin_qty[], char Begin_descrip[], double Units_sold[])
{
    //We are missing Begin_descript  in the next cin statement
    inData>>month>>Item>>Begin_qty[4]>>Units_sold[3]; 
}

// Begin_qty and Units_sold  should not be defined as arrays
//Once Begin_qty and Units_sold have been changed from arrays to normal variable - and they should
// be passed by reference
void Dataout(ofstream &outData,char month[],char Item[], double Begin_qty[], char Begin_descrip[], double Units_sold[])
{
    //These variables can be rationalised.
    double sold,endqty,begin,units;
    begin=Begin_qty;
    units=Units_sold;
    endqty=begin-units;
    sold=units/begin;

    outData<<"Month :"<<month<<"\n\n";
    outData<< "ITEM"<< setw(5)<<"BEGIN QTY"<<setw(5)<<"UNITS SOLD"<<setw(5)<<"ENDING QTY"<<setw(5)<<"SOLD\n";
    outData<<Item<<setw(5)<<Begin_qty<<setw(5)<<Begin_descrip<<setw(5)<<Units_sold<<setw(5<<endqty<<setw(5)<<sold;

}
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
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <fstream>

using namespace std;

void Datain(ifstream &inData, char month[10], char Item[13], double Begin_qty, char Begin_descrip[10], double Units_sold);

void Dataout(ofstream &outData,char month[10], char Item[13], double Begin_qty, char Begin_descrip[10], double Units_sold);


int main ()

{

    ifstream inData;
    char month[10];
    char Item[13];
    double Begin_qty; 
    char Begin_descrip[10];
    double Units_sold; 
    ofstream outData;

    char file[15];
    cout<< "Please enter Filename :";
    cin>>file;
    inData.open(file);

    char ofile[15];
    cout<<"Please enter Filename to save :";
    cin>>ofile;
    outData.open (ofile);
    system("cls");

    while (!inData.fail())// It should loop till there is no more data but it doesn't seem to be working.
    {
        Datain(inData, month,Item, Begin_qty, Begin_descrip, Units_sold);
        if(!inData.fail())
        Dataout(outData, month,Item,Begin_qty,Begin_descrip, Units_sold);
    }

    return 0;
}



void Datain(ifstream &inData, char month[],char Item[], double Begin_qty, char Begin_descrip[], double Units_sold)
{
    
    inData>>month>>Item>>Begin_qty>>Begin_descrip[10]>>Units_sold;// double is not reading data in. 
}


void Dataout(ofstream &outData,char month[],char Item[], double Begin_qty, char Begin_descrip[], double Units_sold)
{
    double sold,endqty,begin,units;
    begin=Begin_qty;
    units=Units_sold;
    endqty=begin-units;
    sold=units/begin;

    outData<<"Month :"<<month<<"\n\n";//OutData is not printing to file.
    outData<< "ITEM"<< setw(5)<<"BEGIN QTY"<<setw(5)<<"UNITS SOLD"<<setw(5)<<"ENDING QTY"<<setw(5)<<"SOLD\n";
    outData<<Item<<setw(5)<<Begin_qty<<setw(5)<<Begin_descrip<<setw(5)<<Units_sold<<setw(5)<<endqty<<setw(5)<<sold;

}
I know double won't read the data in as you have written it.
That because when you call the Datain function you are passing begin_qty and Units_sold by value.
So the variables being changed are copies of the original and are local to the Datain function.

Please see my previous comments about passing by reference.
but the out data still won't work
One thing at a time.
 
inData>>month>>Item>>Begin_qty>>Begin_descrip[10]>>Units_sold;// double is not reading data in.  


Problem is Begin_descrip[10] - only one character is being
read!!! and this was messing everything up.
It should be :
inData>>month>>Item>>Begin_qty>>Begin_descrip>>Units_sold;

You will not see anything in the output file until the output file is closed.
As you don't have any file close commands - the file will not close until the program terminates and the system flushes all the buffers.
But it has been written to the file

So with everything taken into account so far and modifying the Dataout
function which had a couple of mistakes - including incorrect calculation of percentage sold where you forgot to multiply by 100,
you should have something similar to this:
(Note I have put the description as part of the output - I'm not sure if that was required)

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
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <fstream>

using namespace std;


void Datain(ifstream &inData, char month[], char Item[], double &Begin_qty, char Begin_descrip[], double &Units_sold);
void Dataout(ofstream &outData,char month[], char Item[], double &Begin_qty, char Begin_descrip[], double &Units_sold);


int main ()

{

    ifstream inData;
    char month[10];
    char Item[13];
    double Begin_qty; 
    char Begin_descrip[10];
    double Units_sold; 
    ofstream outData;

    char file[15];
    cout<< "Please enter Filename :";
    cin>>file;
    inData.open(file);

    char ofile[15];
    cout<<"Please enter Filename to save :";
    cin>>ofile;
    outData.open (ofile);
    system("cls");

    while (!inData.fail())
    {
        Datain(inData, month,Item, Begin_qty, Begin_descrip, Units_sold);
        if(!inData.fail())
        Dataout(outData, month,Item,Begin_qty,Begin_descrip, Units_sold);
    }

    inData.close();
    outData.close(); //flush output file to disk.

    return 0;
}



void Datain(ifstream &inData, char month[],char Item[], double &Begin_qty, char Begin_descrip[], double &Units_sold)
{  
    inData>>month>>Item>>Begin_qty >> Begin_descrip  >>Units_sold;
}


void Dataout(ofstream &outData,char month[],char Item[], double &Begin_qty, char Begin_descrip[], double &Units_sold)
{
    
    double sold,endqty;
    endqty=Begin_qty - Units_sold;
    sold= 100* Units_sold / Begin_qty; //if you want PERCENTAGE you have to multiply by 100;

    outData<< "\n\n" << "Month :"<<month<<"\n\n";
    outData << left << setw(15) << "ITEM"<< setw(11) << "BEGIN_QTY" << setw(12) << "DESCRIPT"    <<setw(12) << "UNITS_SOLD" <<setw(12) << "ENDING_QTY" << setw(5) << "% SOLD\n";
    outData         << setw(15) << Item  << setw(11) << Begin_qty   << setw(12) << Begin_descrip <<setw(12) << Units_sold   <<setw(12) << endqty       << setw(5) << sold;

}
thank you
Topic archived. No new replies allowed.