A
Aamir Wahid
Hi
i was trying to run a code in c++.net and i got this following error
warning C4267: '=' : conversion from 'size_t' to 'int', possible loss
of data
i am putting my code here if any body correct that error i will be
really appreciate it.
thanks
Aamir
----- CODE --------
#include<iostream>
#include<iomanip>
#include<cctype>
#include<cstring>
#include<cstdlib>
using namespace std;
short mindate =1990;
short maxdate = 2020;
const int num1=25;
struct CustRec
{
short cid;
char pkg;
float hrs;
char date[10];
char msg[30];
};
CustRec customers[num1]= {{100,'A',18,"07182003"},
{101,'d',31,"07192003"},
{102,'b',697,"02022000"},
{103,'C',673,"02021999"},
{104,'a',745,"01311998"},
{105,'B',14,"03051989"},
{106,'c',25,"13051990"},
{107,'C',47,"06311995"},
{108,'a',53,"12345567"},
{109,'b',255,"123456789"},
{110,'D',47,"06311995"},
{120,'C',47,"0A311995"},
{130,'C',47,"0630199A"},
{140,'C',47,"000311995"},
{150,'C',47,"02291995"},
{160,'C',47,"02292000"},
{170,'C',47,"02281995"},
{180,'C',47,"09311995"},
{190,'C',47,"09311995"},
{200,'C',47,"04082020"},
{210,'C',47,"063119"},
{220,'C',0,"05151990"},
{230,'C',47,"03312003"},
{240,'C',47,"06012000"},
{250,'C',47,"07312005"}, //SHORT LENGTH
};
void valrecord(CustRec[],int &,int &,int &);
bool valpkg(CustRec);
bool vallength(CustRec);
bool valdigit(CustRec);
bool valmonth(CustRec,int &, int &, int &);
bool valyear(CustRec, int &);
bool valday(CustRec,int &, int &, int &);
bool valhour(CustRec, int &, int &, int &);
void parseDate(CustRec,int &, int &, int &);
void showdata(CustRec[]);
void main()
{
int nyear=0;
int nmonth =0;
int nday =0;
valrecord(customers,nyear,nmonth,nday);
showdata(customers);
}
void valrecord(CustRec customers[],int &nyear, int &nmonth, int &nday)
{
for(int i=0;i<num1; i++)
{
if(valpkg(customers)==false)
{
strcpy(customers.msg, "invalid pakage");
}
else if(vallength(customers)==false)
{
strcpy(customers.msg, "invalid length pakage");
}
else if(valdigit(customers)==false)
{
strcpy(customers.msg, "invalid digit number");
}
else if(valmonth(customers,nyear,nmonth,nday)== false)
{
strcpy(customers.msg, "invalid month");
}
else if(valday(customers,nyear,nmonth,nday)==false)
{
strcpy(customers.msg, "invalid day");
}
else if(valyear(customers,nyear)==false)
{
strcpy(customers.msg, "invalid year");
}
else if(valhour(customers,nyear,nmonth,nday)==false)
{
strcpy(customers.msg, "invalid hour");
}
}
}
bool valpkg(CustRec customers)
{
if (toupper(customers.pkg)=='A' || toupper(customers.pkg)=='B' ||
toupper(customers.pkg)=='C')
return true;
else
return false;
}
//
bool vallength(CustRec customers)
{
int len1;
len1 = strlen(customers.date);
if(len1!=8)
return false;
else
return true;
}
bool valdigit(CustRec customers)
{
for(int count=0;count < 10;count++)
{
if(isalpha(customers.date[count]))
return false;
}
return true;
}
bool valmonth(CustRec customers,int &nyear,int &nmonth,int &nday)
{
parsedate(customers,nyear,nmonth,nday);
if(nmonth >= 1 && nmonth <= 13)
return true;
else
return false;
}
bool valday(CustRec customers,int &nyear,int &nmonth,int &nday)
{
int chDay[12]={31,28,31,30,31,30,31,31,30,31,30,31};
if(nmonth==2)
{
if(nyear % 4==0)
if((nday > 0) && (nday <=29))
return true;
else
return false;
else if((nday > 0)&& (nday <=28))
return true;
else
return false;
}
else if((nday > 0)&& (nday <=chDay[nmonth -1]))
return true;
else
return false;
}
bool valyear(CustRec customers,int &nyear)
{
if((nyear < mindate) || (nyear > maxdate))
return false;
else
return true;
}
bool valhour(CustRec customers,int &nyear,int &nmonth,int &nday)
{
int checkhour[12]={744,672,744,720,744,720,744,744,720,744,720,744};
if(nmonth==2)
{
if(nyear %4 == 0)
if (customers.hrs >=0 && customers.hrs <=696)
return true;
else
return false;
if (customers.hrs >=0 && customers.hrs <=672)
return true;
else
return false;
}
else
if (customers.hrs >=0 && customers.hrs <=checkhour[nmonth-1])
return true;
else
return false;
}
void parsedate(CustRec customers,int &nyear,int &nmonth,int &nday)
{
char year[5];
char month[3];
char day[3];
for (int i=4,j=0;i<8;i++,j++)
{
year[j]=customers.date;
}
year[j]='\0';
nyear =atoi(year);
for (int i=0,j=0;i<2;i++,j++);
{
month[j]=customers.date;
}
month[j]='\0';
nmonth= atoi(month);
for (int i=2,j=0;i<4;i++,j++)
{
day[j]=customers.date;
}
day[j]= '\0';
nday=atoi(day);
}
void showdata(CustRec customers[])
{
for(int i=0;i<num1;i++)
{
cout<<customers.cid <<" "
<<customers.pkg <<" "
<<customers.hrs <<" "
<<customers.date <<" "
<<customers.msg <<endl;
}
}
i was trying to run a code in c++.net and i got this following error
warning C4267: '=' : conversion from 'size_t' to 'int', possible loss
of data
i am putting my code here if any body correct that error i will be
really appreciate it.
thanks
Aamir
----- CODE --------
#include<iostream>
#include<iomanip>
#include<cctype>
#include<cstring>
#include<cstdlib>
using namespace std;
short mindate =1990;
short maxdate = 2020;
const int num1=25;
struct CustRec
{
short cid;
char pkg;
float hrs;
char date[10];
char msg[30];
};
CustRec customers[num1]= {{100,'A',18,"07182003"},
{101,'d',31,"07192003"},
{102,'b',697,"02022000"},
{103,'C',673,"02021999"},
{104,'a',745,"01311998"},
{105,'B',14,"03051989"},
{106,'c',25,"13051990"},
{107,'C',47,"06311995"},
{108,'a',53,"12345567"},
{109,'b',255,"123456789"},
{110,'D',47,"06311995"},
{120,'C',47,"0A311995"},
{130,'C',47,"0630199A"},
{140,'C',47,"000311995"},
{150,'C',47,"02291995"},
{160,'C',47,"02292000"},
{170,'C',47,"02281995"},
{180,'C',47,"09311995"},
{190,'C',47,"09311995"},
{200,'C',47,"04082020"},
{210,'C',47,"063119"},
{220,'C',0,"05151990"},
{230,'C',47,"03312003"},
{240,'C',47,"06012000"},
{250,'C',47,"07312005"}, //SHORT LENGTH
};
void valrecord(CustRec[],int &,int &,int &);
bool valpkg(CustRec);
bool vallength(CustRec);
bool valdigit(CustRec);
bool valmonth(CustRec,int &, int &, int &);
bool valyear(CustRec, int &);
bool valday(CustRec,int &, int &, int &);
bool valhour(CustRec, int &, int &, int &);
void parseDate(CustRec,int &, int &, int &);
void showdata(CustRec[]);
void main()
{
int nyear=0;
int nmonth =0;
int nday =0;
valrecord(customers,nyear,nmonth,nday);
showdata(customers);
}
void valrecord(CustRec customers[],int &nyear, int &nmonth, int &nday)
{
for(int i=0;i<num1; i++)
{
if(valpkg(customers)==false)
{
strcpy(customers.msg, "invalid pakage");
}
else if(vallength(customers)==false)
{
strcpy(customers.msg, "invalid length pakage");
}
else if(valdigit(customers)==false)
{
strcpy(customers.msg, "invalid digit number");
}
else if(valmonth(customers,nyear,nmonth,nday)== false)
{
strcpy(customers.msg, "invalid month");
}
else if(valday(customers,nyear,nmonth,nday)==false)
{
strcpy(customers.msg, "invalid day");
}
else if(valyear(customers,nyear)==false)
{
strcpy(customers.msg, "invalid year");
}
else if(valhour(customers,nyear,nmonth,nday)==false)
{
strcpy(customers.msg, "invalid hour");
}
}
}
bool valpkg(CustRec customers)
{
if (toupper(customers.pkg)=='A' || toupper(customers.pkg)=='B' ||
toupper(customers.pkg)=='C')
return true;
else
return false;
}
//
bool vallength(CustRec customers)
{
int len1;
len1 = strlen(customers.date);
if(len1!=8)
return false;
else
return true;
}
bool valdigit(CustRec customers)
{
for(int count=0;count < 10;count++)
{
if(isalpha(customers.date[count]))
return false;
}
return true;
}
bool valmonth(CustRec customers,int &nyear,int &nmonth,int &nday)
{
parsedate(customers,nyear,nmonth,nday);
if(nmonth >= 1 && nmonth <= 13)
return true;
else
return false;
}
bool valday(CustRec customers,int &nyear,int &nmonth,int &nday)
{
int chDay[12]={31,28,31,30,31,30,31,31,30,31,30,31};
if(nmonth==2)
{
if(nyear % 4==0)
if((nday > 0) && (nday <=29))
return true;
else
return false;
else if((nday > 0)&& (nday <=28))
return true;
else
return false;
}
else if((nday > 0)&& (nday <=chDay[nmonth -1]))
return true;
else
return false;
}
bool valyear(CustRec customers,int &nyear)
{
if((nyear < mindate) || (nyear > maxdate))
return false;
else
return true;
}
bool valhour(CustRec customers,int &nyear,int &nmonth,int &nday)
{
int checkhour[12]={744,672,744,720,744,720,744,744,720,744,720,744};
if(nmonth==2)
{
if(nyear %4 == 0)
if (customers.hrs >=0 && customers.hrs <=696)
return true;
else
return false;
if (customers.hrs >=0 && customers.hrs <=672)
return true;
else
return false;
}
else
if (customers.hrs >=0 && customers.hrs <=checkhour[nmonth-1])
return true;
else
return false;
}
void parsedate(CustRec customers,int &nyear,int &nmonth,int &nday)
{
char year[5];
char month[3];
char day[3];
for (int i=4,j=0;i<8;i++,j++)
{
year[j]=customers.date;
}
year[j]='\0';
nyear =atoi(year);
for (int i=0,j=0;i<2;i++,j++);
{
month[j]=customers.date;
}
month[j]='\0';
nmonth= atoi(month);
for (int i=2,j=0;i<4;i++,j++)
{
day[j]=customers.date;
}
day[j]= '\0';
nday=atoi(day);
}
void showdata(CustRec customers[])
{
for(int i=0;i<num1;i++)
{
cout<<customers.cid <<" "
<<customers.pkg <<" "
<<customers.hrs <<" "
<<customers.date <<" "
<<customers.msg <<endl;
}
}