How do you write a function with integers used outside without using globals?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lordhoban
    New Member
    • Nov 2009
    • 8

    How do you write a function with integers used outside without using globals?

    I've been trying to get this, but no matter what method I try, nothing works and the book shows only the most simplistic examples. I have other functions currently that run, but with global values. I want to fix it all, but to do that, I need to get the following function to work:

    function prototype:
    int ToTaling(int &,int &,int &,int &,int &,int &,int &,int &,int &);
    (OR)
    //int &TotalRate, int &TotalRegHou rs, int &TotalOvtHou rs, int &TotalGrossP ay,
    // int &TotalFedTax , int &TotalStateT ax, int &TotalSSITax , int &TotalDeferr ed,
    // int &TotalNet);
    (I tried it with the actual names, I tried it with * instead of ampersand, what am I missing here? I've also tried void at the beginning. Nothing seems to work.)

    (inside main)
    int TotalRate, TotalRegHours, TotalOvtHours, TotalGrossPay, TotalFedTax,
    TotalStateTax,T otalSSITax, TotalDeferred,T otalNet;

    ToTaling(&Total Rate,&TotalRegH ours,&TotalOvtH ours,&TotalGros sPay,
    &TotalFedTax,&T otalStateTax,&T otalSSITax,&Tot alDeferred,
    &TotalNet);


    And then the function outside the main:
    {
    int J = 0;
    while (J<=H){
    TotalRate=Total Rate+Payrate[J]; // equals Total += Hours[J+1];
    TotalRegHours=T otalRegHours+Re gHours[J]; // equals Total += Hours[J+1];
    TotalOvtHours=T otalOvtHours+Ov tHours[J];
    TotalGrossPay=T otalGrossPay+Ca lcGross[J];
    TotalFedTax=Tot alFedTax+calcFe d[J];
    TotalStateTax=T otalStateTax+ca lcState[J];
    TotalSSITax=Tot alSSITax+calcSS i[J];
    TotalDeferred=T otalDeferred+De ferred[J];
    TotalNet=TotalN et+NetPay[J]; // equals Total += Hours[J+1];
    J=J+1;
    }

    return (TotalRate, TotalRegHours, TotalOvtHours, TotalGrossPay, TotalFedTax,Tot alStateTax, TotalSSITax, TotalDeferred, TotalNet);
    }

    The current error I'm getting is : cannot convert parameter 1 from 'int *' to 'int &' ....
    The following line:
    &TotalNet); (in the main, though probably the entire thing!)

    Thanks for any and all help!
  • JonathanS
    New Member
    • Jan 2008
    • 37

    #2
    Code:
    ToTaling(&TotalRate,&TotalRegHours,&TotalOvtHours, &TotalGrossPay,
    &TotalFedTax,&TotalStateTax,&TotalSSITax,&TotalDef erred,
    &TotalNet);
    Should not use the ampersands when you call it in main. Also, you don't need to have a return statement if you're passing/returning things by reference, so your function can have the return type void.

    I know they're boring but reread those simple examples and see if you can tell what exactly is happening in memory (what are the references referencing)

    Comment

    • lordhoban
      New Member
      • Nov 2009
      • 8

      #3
      I got the function running, thanks to your very on target advice. Now the issue is the output. -107374160 --It's giving me these values in return instead of the actual number.

      Do I need a special character to reference back to it when printing the value to a file?

      I tried going back to the examples and they're very unhelpful. A few little helpful hints from you and I'm actually getting somewhere...

      Comment

      • RRick
        Recognized Expert Contributor
        • Feb 2007
        • 463

        #4
        The return value for Taling looks bad
        return (TotalRate, TotalRegHours, TotalOvtHours, TotalGrossPay, TotalFedTax,Tot alStateTax, TotalSSITax, TotalDeferred, TotalNet);
        I'm not sure how to read this return value into an array or separate variables.

        Also, it looks like you don't need to have ToTaling return anything because the parameters are passed by reference, and their values are changed directly by the subroutine.

        Comment

        • JonathanS
          New Member
          • Jan 2008
          • 37

          #5
          Run your code through a good debugger and find out where the value is getting scrambled. Did you leave in one of the ampersands when you call your function in main? If you're not comfortable with the debugger pepper your code with cout statements to trace it. I can't begin to know where that value comes from but it's most likely an address or possibly due to an overflow.

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            Originally posted by lordhoban
            I got the function running, thanks to your very on target advice. Now the issue is the output. -107374160 --It's giving me these values in return instead of the actual number.
            It may be useful to post the code you are using to output the values as well. For instance if you have more misplaced & you will be getting the wrong values because you will be getting the memory addresses of the integers not the integers themselves.

            Comment

            • lordhoban
              New Member
              • Nov 2009
              • 8

              #7
              Updated Code (all the code relevant to the problem at hand. I don't have any errors, but I do have warnings about converting float to int. Could that be causing it?):
              Prototype:
              Code:
              void ToTaling(int &,int &,int &,int &,int &,int &,int &,int &,int &);
              
              #define REPORTFORMAT7 "Totals \n"
              #define REPORTFORMAT5 "                %3.2d%11.2d %13.2d %9.2d %11.2d%10.2d\n"
              #define REPORTFORMAT6 "                          %4.2d%24.2d %11.2d\n"
              
              
              Main body:
              int TotalRate, TotalRegHours, TotalOvtHours, TotalGrossPay, TotalFedTax,
              	TotalStateTax,TotalSSITax, TotalDeferred,TotalNet;
              
              ToTaling(TotalRate,TotalRegHours,TotalOvtHours,TotalGrossPay,
              TotalFedTax,TotalStateTax,TotalSSITax,TotalDeferred, TotalNet);
              
              fprintf(reportFile,REPORTFORMAT7);
              fprintf (reportFile,REPORTFORMAT, TotalRate,TotalRegHours,TotalGrossPay, TotalFedTax,TotalSSITax,TotalNet); 
              fprintf(reportFile,REPORTFORMAT ,TotalOvtHours,TotalStateTax,TotalDeferred);
              
              AND ACTUAL function:
              void ToTaling(int &TotalRate, int &TotalRegHours, int &TotalOvtHours, int &TotalGrossPay,
               int &TotalFedTax, int &TotalStateTax, int &TotalSSITax, int &TotalDeferred,
               int &TotalNet)
              {
              	int J = 0;
              	while (J<=H){
              	TotalRate=TotalRate+Payrate[J]; // equals Total += Hours[J+1];
              	TotalRegHours=TotalRegHours+RegHours[J]; // equals Total += Hours[J+1];
              	TotalOvtHours=TotalOvtHours+OvtHours[J]; 
              	TotalGrossPay=TotalGrossPay+CalcGross[J]; 
              	TotalFedTax=TotalFedTax+calcFed[J]; 
              	TotalStateTax=TotalStateTax+calcState[J]; 
              	TotalSSITax=TotalSSITax+calcSSi[J]; 
              	TotalDeferred=TotalDeferred+Deferred[J]; 
              	TotalNet=TotalNet+NetPay[J]; // equals Total += Hours[J+1];
              	J=J+1;
              		}
              
              
              }
              The function code worked fine when it was in the main body, so since putting it in a function, I'm guessing it has to do with how the fprint is reading it... Maybe an ampersand or something needs to be there?

              Comment

              • JonathanS
                New Member
                • Jan 2008
                • 37

                #8
                What is H in your function? Is it possible you want J<H? if you're writing too far on your array you might be corrupting the memory surrounding it. One way to check the fprintf is to test it with a plain printf. It could be your formatting but that looks ok.

                Comment

                • lordhoban
                  New Member
                  • Nov 2009
                  • 8

                  #9
                  H is the universal counter. Basically, H is added onto for every record that was added to the report. So every record in each array will be totalled. I'll do a printf test.

                  Comment

                  • lordhoban
                    New Member
                    • Nov 2009
                    • 8

                    #10
                    I did the printf test and it produced the same output. I've tried making the values float, and they just produce different wacky output.

                    Could it have anything to do with the arrays being global values? They worked fine when everything was in the main body, but maybe it is having problems calculating inside the function with the global arrays?

                    If so, I don't know how to make the arrays work if they're not global.

                    Comment

                    • lordhoban
                      New Member
                      • Nov 2009
                      • 8

                      #11
                      Ok, here is the entire code. Maybe the errors will tell you something they don't tell me... I even included in //, where the function code used to be before being moved outside of the main body.

                      Code:
                      #include <stdio.h>
                      #include <stdlib.h>
                      
                      //Report Print Out
                      #define REPORTHEADER "Employee         Pay       Reg Hrs       Gross      Fed        SSI      Net\n"
                      #define REPORTHEADER2 "Name             Rate      Ovt Hrs       Pay        State      Defr     Pay\n"
                      #define REPORTHEADER3  "========         ====      =======       =====      =====      ====     ===\n\n"
                      #define REPORTFORMAT3 "%-2s, %-10s\n"
                      #define REPORTFORMAT "                %6.2f%11.2f %13.2f %9.2f%11.2f%10.2f\n"
                      #define REPORTFORMAT2 "                           %6.2f%24.2f%11.2f\n\n"
                      #define REPORTFORMAT7 "Totals \n"
                      #define REPORTFORMAT5 "                %3.2d%11.2d %13.2d %9.2d %11.2d%10.2d\n"
                      #define REPORTFORMAT6 "                          %4.2d%24.2d %11.2d\n"
                      #define REPORTFORMAT4 "Averages \n"
                      #define REPORTFORMAT8 "                %3.2d%11.2d %13.2d %9.2d %11.2d%10.2d\n"
                      #define REPORTFORMAT9 "                          %4.2d%24.2d %11.2d\n"
                      
                      
                      //Tax Header
                      #define FEDTAXRATE 0.15
                      #define STATERATE 0.07
                      #define SSIRATE 0.0775
                      
                      //Declaring variables
                      float calcFed[100]; //3.5.1
                      float calcState[100]; //3.5.2
                      float calcSSi[100]; //3.5.3
                      float Hours[100], OvtHours[100], RegHours[100], Payrate[100], CalcGross[100], Deferred[100], TotTax;
                      float NetPay[100]; // No instructions on Netpay, so I had to guess based on what the internet said of Netpay
                      char FName[9],LName[9];
                      char More; //Choice variable
                      int H,AvgRate, AvgReg,
                      				AvgOvt, AvgGross, AvgFed, AvgState, AvgSSI, AvgNet, AvgDef;
                      
                      void HeaD();
                      int Ohours(int);
                      //int Rhours(int);
                      int GrOssP(int);
                      int tAxes(int);
                      void ToTaling(int &,int &,int &,int &,int &,int &,int &,int &,int &);
                      			 //int &TotalRate, int &TotalRegHours, int &TotalOvtHours, int &TotalGrossPay,
                      //			 int &TotalFedTax, int &TotalStateTax, int &TotalSSITax, int &TotalDeferred,
                      //			 int &TotalNet);
                      
                      
                      void HeaD()
                      {
                      	FILE * reportFile; // create FILE * variable
                      
                      	reportFile = fopen("./report.txt","wt"); // To open the file
                      	if (reportFile == NULL) // To give an error message if file doesn't open.
                      	{
                      		printf("  Report file failed to open ...\n");
                      		exit(-10); // reqs <stdlib.h>
                      	}
                      	fprintf(reportFile,REPORTHEADER); // Printing the Header files.
                      	fprintf(reportFile,REPORTHEADER2); // Printing the Header files.
                      	fprintf(reportFile,REPORTHEADER3); // Printing the Header files.
                      	fclose(reportFile); // close the file
                      	fflush(stdin);
                      }
                      
                      
                      int main(void)
                      {
                      
                      int TotalRate, TotalRegHours, TotalOvtHours, TotalGrossPay, TotalFedTax,
                      	TotalStateTax,TotalSSITax, TotalDeferred,TotalNet;
                      
                      	printf("Input a record? Yes(y) or No(n)?");
                      	scanf("%s",&More);
                      	if (More!='y'&&More!='Y')exit(-10);
                      	
                      	HeaD();
                      
                      while (More=='y'||More=='Y') //Begin main while loop
                      {
                      	FILE * reportFile; // create FILE * variable
                      
                      	reportFile = fopen("./report.txt","a+"); // To open the file
                      	if (reportFile == NULL)
                      	{
                      		printf("  Report file failed to open ...\n");
                      		exit(-10); 
                      	}
                      
                      	//Inputting information
                      	printf("Input Employee's First Name: \n");
                      	scanf("%s",&FName);
                      	printf("Input Employee's Last Name: \n");
                      	scanf("%s",&LName);
                      	printf("Input Hours worked: \n");
                      	scanf("%f",&Hours[H+1]);
                      	printf("Enter Employee's Payrate: \n");
                      	scanf("%f",&Payrate[H+1]);
                      	printf("Enter Deferred Payment: \n");
                      	scanf("%f",&Deferred[H+1]);
                      
                      	Ohours(OvtHours[H+1]);
                      //	Rhours(RegHours[H+1]);
                      	GrOssP(CalcGross[H+1]);
                      	tAxes(calcFed[H+1]);
                      
                      		H=H+1; //accumilator
                      
                      		//The following prints to screen some info you just entered.
                      		printf("Employee Name: %-2s, %-10s\n\n", LName, FName); 
                      		printf("Over Time: %.2f hours\n\n", OvtHours[H]);
                      		printf("Gross Pay: %.2f\n\n", CalcGross[H]);
                      		printf("Net Pay: %.2f\n\n", NetPay[H]);
                      
                      
                      	//First part of putting values in a file.
                      	fprintf(reportFile,REPORTFORMAT3,LName,FName);
                        	fprintf(reportFile,REPORTFORMAT,Payrate[H],RegHours[H],CalcGross[H],calcFed[H],calcSSi[H],NetPay[H]);
                      	fprintf(reportFile,REPORTFORMAT2,OvtHours[H],calcState[H],Deferred[H]);
                      
                      	fclose(reportFile); // close the file
                      	fflush(stdin);
                      
                      			//The following allows the user to choose whether to keep computating.
                      	printf("Input another record? Yes(y) or No(n)?");
                      	scanf("%s",&More);
                      }
                      	FILE * reportFile; // create FILE * variable
                      	reportFile = fopen("./report.txt","a+"); // To open the file
                      
                      	if (reportFile == NULL)
                      	{
                      		printf("  Report file failed to open ...\n");
                      		exit(-10); 
                      	}
                      
                      	ToTaling(TotalRate,TotalRegHours,TotalOvtHours,TotalGrossPay,
                      			 TotalFedTax,TotalStateTax,TotalSSITax,TotalDeferred,
                      			 TotalNet);
                      	  //Total Functions for each of the numerical columns
                      //		int TotalRate=0,TotalRegHours=0,TotalOvtHours=0,TotalGrossPay=0,
                      //			TotalFedTax=0,TotalStateTax=0,TotalSSITax=0,TotalDeferred=0,
                      //			TotalNet=0;
                      //	int J = 0;
                      //		while (J<=H){
                      //			TotalRate=TotalRate+Payrate[J]; // equals Total += Hours[J+1];
                      //			TotalRegHours=TotalRegHours+RegHours[J]; // equals Total += Hours[J+1];
                      //			TotalOvtHours=TotalOvtHours+OvtHours[J]; 
                      //			TotalGrossPay=TotalGrossPay+CalcGross[J]; 
                      //			TotalFedTax=TotalFedTax+calcFed[J]; 
                      //			TotalStateTax=TotalStateTax+calcState[J]; 
                      //			TotalSSITax=TotalSSITax+calcSSi[J]; 
                      //			TotalDeferred=TotalDeferred+Deferred[J]; 
                      //			TotalNet=TotalNet+NetPay[J]; // equals Total += Hours[J+1];
                      //		J=J+1;
                      //		}
                      			//Averaging equations.
                      		int AvgRate = TotalRate/H;
                      		int AvgReg = TotalRegHours/H;
                      		int AvgOvt = TotalOvtHours/H;
                      		int AvgGross = TotalGrossPay/H;
                      		int AvgFed = TotalFedTax/H;
                      		int AvgState = TotalStateTax/H;
                      		int AvgSSI = TotalSSITax/H;
                      		int AvgNet = TotalNet/H;
                      		int AvgDef = TotalDeferred/H;
                      
                      //Final part of the report
                      printf(REPORTFORMAT5,TotalRate,TotalRegHours,TotalGrossPay,TotalFedTax,TotalSSITax,TotalNet);
                      	fprintf(reportFile,"\n\n");
                      	fprintf(reportFile,REPORTFORMAT7);
                      	fprintf(reportFile,REPORTFORMAT5,TotalRate,TotalRegHours,TotalGrossPay,TotalFedTax,TotalSSITax,TotalNet);
                      	fprintf(reportFile,REPORTFORMAT6,TotalOvtHours,TotalStateTax,TotalDeferred);
                      	fprintf(reportFile,"\n\n");
                      	fprintf(reportFile,REPORTFORMAT4);
                      	fprintf(reportFile,REPORTFORMAT8,AvgRate,AvgReg,AvgGross,AvgFed,AvgSSI,AvgNet);
                      	fprintf(reportFile,REPORTFORMAT9,AvgOvt,AvgState,AvgDef);
                      
                      	fclose(reportFile); // close the file
                      
                      	fflush(stdin);
                      	printf("Press any key and enter...\n");
                      	getchar();
                      	return 0;
                      }
                      
                      int Ohours(int)
                      {
                      	    if (Hours[H+1]>40) 
                      			OvtHours[H+1] = Hours[H+1] - 40; // Determines over time hours
                      		else 
                      			OvtHours[H+1] = 0; // Determines over time hours
                      		if (Hours[H+1]>40) 
                      			RegHours[H+1] = Hours[H+1] - OvtHours[H+1]; // Determines regular hours
                      		else 
                      			RegHours[H+1] = Hours[H+1]; // Determines regular hours
                      		return OvtHours[H+1],RegHours[H+1];
                      }
                      
                      //int Rhours(int)
                      //{
                      //		if (Hours[H+1]>40) 
                      //			RegHours[H+1] = Hours[H+1] - OvtHours[H+1]; // Determines regular hours
                      //		else 
                      //			RegHours[H+1] = Hours[H+1]; // Determines regular hours
                      //		return RegHours[H+1];
                      //}
                      
                      int GrOssP(int)
                      {
                      	if (Hours[H+1]<=40) //Calculating Gross 
                      		{
                                      CalcGross[H+1] = Hours[H+1] * Payrate[H+1];
                              }
                              else{
                                      CalcGross[H+1] = Payrate[H+1] * 40 + ((Hours[H+1] - 40)*1.5*Payrate[H+1]);
                              }
                      		return CalcGross[H+1];
                      }
                      
                      int	tAxes(int)
                      	{
                      			//Calculating all tax based items. The below also takes into account
                      			//having 0 gross pay means no taxes on that pay.
                      		if (CalcGross[H+1]>0)calcFed[H+1] = (FEDTAXRATE * (CalcGross[H+1] - Deferred[H+1]));
                      		if (CalcGross[H+1]>0)calcState[H+1] = (STATERATE * calcFed[H+1]);
                      		if (CalcGross[H+1]>0)calcSSi[H+1] = (STATERATE * (CalcGross[H+1] - Deferred[H+1]));
                      		TotTax=calcFed[H+1]+calcState[H+1]+calcSSi[H+1]; //Combining all tax for...
                      		NetPay[H+1]=CalcGross[H+1]-TotTax; //...defining NetPay
                      		return calcFed[H+1],calcState[H+1],calcSSi[H+1],TotTax,NetPay[H+1];
                      	}
                      
                      
                      	  //Total Functions for each of the numerical columns
                      void ToTaling(int &TotalRate, int &TotalRegHours, int &TotalOvtHours, int &TotalGrossPay,
                      			 int &TotalFedTax, int &TotalStateTax, int &TotalSSITax, int &TotalDeferred,
                      			 int &TotalNet)
                      {
                      	int J = 0;
                      		while (J<=H){
                      			TotalRate=TotalRate+Payrate[J]; // equals Total += Hours[J+1];
                      			TotalRegHours=TotalRegHours+RegHours[J]; // equals Total += Hours[J+1];
                      			TotalOvtHours=TotalOvtHours+OvtHours[J]; 
                      			TotalGrossPay=TotalGrossPay+CalcGross[J]; 
                      			TotalFedTax=TotalFedTax+calcFed[J]; 
                      			TotalStateTax=TotalStateTax+calcState[J]; 
                      			TotalSSITax=TotalSSITax+calcSSi[J]; 
                      			TotalDeferred=TotalDeferred+Deferred[J]; 
                      			TotalNet=TotalNet+NetPay[J]; // equals Total += Hours[J+1];
                      		J=J+1;
                      		}
                      
                      
                      }

                      Comment

                      • Banfa
                        Recognized Expert Expert
                        • Feb 2006
                        • 9067

                        #12
                        You say you are getting compiler errors and warnings but you haven't posted them. Please do post them and if necessary translate the line numbers in the errors so they match your posted code.

                        When post code please don't use [quote] ... [/quote] tags round it, instead use [code] ... [/code] tags which among other things preserve white space..

                        Comment

                        • lordhoban
                          New Member
                          • Nov 2009
                          • 8

                          #13
                          (It won't let me edit the code, so I can't go back and put it in brackets)
                          ERRORS (the fopen/etc type of errors should be ignored, as I will be moving this code into unix, and they need the original fopen type of commands):
                          Code:
                          Warning	1	warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	52	Employ2
                          Warning	2	warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	73	Employ2
                          Warning	3	warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	82	Employ2
                          Warning	4	warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	91	Employ2
                          Warning	5	warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	93	Employ2
                          Warning	6	warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	95	Employ2
                          Warning	7	warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	97	Employ2
                          Warning	8	warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	99	Employ2
                          Warning	9	warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	101	Employ2
                          Warning	10	warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	103	Employ2
                          Warning	11	warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	104	Employ2
                          Warning	12	warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	125	Employ2
                          Warning	13	warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	128	Employ2
                          Warning	14	warning C4244: 'return' : conversion from 'float' to 'int', possible loss of data	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	196	Employ2
                          Warning	15	warning C4244: '=' : conversion from 'double' to 'float', possible loss of data	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	215	Employ2
                          Warning	16	warning C4244: 'return' : conversion from 'float' to 'int', possible loss of data	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	217	Employ2
                          Warning	17	warning C4244: '=' : conversion from 'double' to 'float', possible loss of data	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	224	Employ2
                          Warning	18	warning C4244: '=' : conversion from 'double' to 'float', possible loss of data	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	225	Employ2
                          Warning	19	warning C4244: '=' : conversion from 'double' to 'float', possible loss of data	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	226	Employ2
                          Warning	20	warning C4244: 'return' : conversion from 'float' to 'int', possible loss of data	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	229	Employ2
                          Warning	21	warning C4244: '=' : conversion from 'float' to 'int', possible loss of data	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	240	Employ2
                          Warning	22	warning C4244: '=' : conversion from 'float' to 'int', possible loss of data	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	241	Employ2
                          Warning	23	warning C4244: '=' : conversion from 'float' to 'int', possible loss of data	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	242	Employ2
                          Warning	24	warning C4244: '=' : conversion from 'float' to 'int', possible loss of data	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	243	Employ2
                          Warning	25	warning C4244: '=' : conversion from 'float' to 'int', possible loss of data	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	244	Employ2
                          Warning	26	warning C4244: '=' : conversion from 'float' to 'int', possible loss of data	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	245	Employ2
                          Warning	27	warning C4244: '=' : conversion from 'float' to 'int', possible loss of data	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	246	Employ2
                          Warning	28	warning C4244: '=' : conversion from 'float' to 'int', possible loss of data	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	247	Employ2
                          Warning	29	warning C4244: '=' : conversion from 'float' to 'int', possible loss of data	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	248	Employ2

                          Comment

                          • donbock
                            Recognized Expert Top Contributor
                            • Mar 2008
                            • 2427

                            #14
                            Originally posted by lordhoban
                            Code:
                            Warning	1	warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.	i:\classstructuredpro\latest\latestemploynov16\employmain11.cpp	52	Employ2
                            You should refer to the online help for details. I don't know if you should use the secure versions of these functions. If you decide to use the standard functions then you should disable deprecation. My guess is you do this by defining macro _CRT_SECURE_NO_ WARNINGS at the top of your source file, before you include any headers; but the best thing for you to do is ignore that advice and look it up in your online help.

                            The warning text complains about your use of 'fopen' on line 52 of employmain11.cp p. You actually call 'fopen' on line 51. This is pretty close, but other warnings have larger discrepancies in the line number. This leads me to believe that the code in your post is not a precise copy of employmain11.cp p. That's ok -- we encourage you to post a relevant snippet to increase the signal-to-noise ratio. But we rely on you to modify the compiler warnings so that the line numbers in the warning text refer to the line numbers in your posted snippet. It will be a lot easier to help if you repost the compiler warnings after adjusting the line numbers.

                            Comment

                            Working...