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)
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];
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.
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <fstream>
usingnamespace 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;
}
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.
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)