Thread: "error C2075: '_Tmp' : array initialization needs curly braces", huh?

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    12

    "error C2075: '_Tmp' : array initialization needs curly braces", huh?

    I have to write a program that inputs data for a payroll, puts the info into 3 arrays and then use bubble sort to sort them alphabetically. When I compile I get these errors:

    Error 10 error C2075: '_Tmp' : array initialization needs curly braces
    and
    Error 11 error C2106: '=' : left operand must be l-value

    I marked where I think the errors are coming from.

    Here is my code
    Code:
    #include<iostream>
    #include<iomanip>
    #include<string>
    #include<cmath>
    #include<fstream>
    #include<stdio.h>
    #include<cctype>
    using namespace std;
    void input(char employee[100][100], int hours[100], float payrolldata[100][100], double& r, char& l, int& d, int& y);
    void grosspay(char employee[100][100], int hours[100], float payrolldata[100][100], double& r, char& l, int& d, int& y);
    void fedtax(float payrolldata[100][100], int& y);
    void fica(float payrolldata[100][100], int& y);
    void healthcare(float payrolldata[100][100], int& y, int& d, char& l);
    void netpay(float payrolldata[100][100], int& y);
    void bubbledown(char employee[100][100], int hours[100], float payrolldata[100][100], int& y);
    int main()
    {
    	char employee[100][100];
    	int hours[100];
    	float payrolldata[100][100];
    	double r;
    	char l;
    	char x='y';
    	int d=0;
    	int y=0;
    	while(x=='y')
    	{
    		input(employee, hours, payrolldata, r, l, d, y);
    		cout << endl << "Add another employee?(y/n): ";
    		cin >> x;
    		cin.ignore();
    	}
    	bubbledown(employee, hours, payrolldata, y);
    	return 0;
    }
    void input(char employee[100][100], int hours[100], float payrolldata[100][100], double& r, char& l, int& d, int& y)
    {	
    	char tempname[100];
    	int m, t, w, h, f, s, u, total;
    	cout <<"Hello, Please enter the following information for the Payroll Report." <<endl;
    	cout << "Name: ";
    	cin.get(tempname, 30, '\n');
    	strcpy(employee[y], tempname);
    	cout << endl << "Hours worked per day: ";
    	cin >> m >> t >> w >> h >> f >> s >> u;
    	total = m+t+w+h+f+s+u;
    	hours[y]= total;
    	cout << endl << "Pay rate:";
    	cin >> r;
    	cout << endl << "Dependents: ";
    	cin >> d;
    	cout << endl << "Health(y/n): ";
    	cin >> l;
    	grosspay(employee, hours, payrolldata, r, l, d, y);
    	fedtax(payrolldata, y);
    	fica(payrolldata, y);
    	healthcare(payrolldata, y, d, l);
    	netpay(payrolldata, y);
    	y++;
    }
    void grosspay(char employee[100][100], int hours[100], float payrolldata[100][100], double& r, char& l, int& d, int& y)
    {
    	cin.ignore();
    	int overtime;
    	int overtimepay;
    	int standard;
    	float grosspay;
    	if(hours[y]>40)
    	{
    		overtime = hours[y] - 40;
    		overtimepay = overtime * r * 1.5;
    		standard = 40 * r;
    		grosspay = standard + overtimepay;
    		payrolldata[y][1]=grosspay;
    
    	}
    	if(hours[y]<=40)
    	{
    		grosspay=hours[y]*r;
    		payrolldata[y][1]=grosspay;
    	}
    	cout << endl << payrolldata[y][1];
    }
    void fedtax(float payrolldata[100][100],int& y)
    {
    	if(payrolldata[y][1] > 300)
    	{
    		payrolldata[y][2]=(.22)*payrolldata[y][1];
    	}
    	if(payrolldata[y][1] <= 300)
    	{
    		payrolldata[y][2]=0;
    	}
    	cout << endl << payrolldata[y][2];
    }
    void fica(float payrolldata[100][100], int& y)
    {
    	double tax;
    	tax = .085 * payrolldata[y][1];
    	if(tax<=45)
    	{
    		payrolldata[y][3]=.085*payrolldata[y][1];
    	}
    	if(tax>45)
    	{
    		payrolldata[y][3] = 45;
    	}
    	cout << endl << payrolldata[y][3];
    }
    void healthcare(float payrolldata[100][100], int& y, int& d, char& l)
    {
    	double dependents;
    	if(l == 'y' || l == 'Y')
    	{
    		if(d==1)
    		{
    			payrolldata[y][4]=18.75;
    		}
    		if(d>=1)
    		{
    			d = d - 1;
    			dependents= d * 7.35;
    			payrolldata[y][4]= 18.75 + dependents;
    		}
    	}
    	if(l != 'y')
    		payrolldata[y][4]=0;
    	cout << endl << payrolldata[y][4];
    }
    void netpay(float payrolldata[100][100], int& y)
    {
    	double taxes;
    	taxes = payrolldata[y][4] + payrolldata[y][3] + payrolldata[y][2];
    	cout << endl <<taxes;
    	payrolldata[y][5] = payrolldata[y][1] - taxes;
    	cout << endl << payrolldata[y][5];
    }
    void bubbledown(char employee[100][100], int hours[100], float payrolldata[100][100], int& y)
    {
    	int i, j;
    	for (i=0; i < y; i++)
    	{
    		for(j=0; j<i; j++)
    		{
    			if(employee[i]<employee[j])
    			{
    				swap(employee[i], employee[j]);         //I think the problem is in here
    				swap(hours[i], hours[j]);               //because when I delete it I don't
    				swap(payrolldata[i], payrolldata[j]);   // get the errors.
    			}
    		}
    	}
    }
    Any help would be great, thanks.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    The error seems to be occurring in the implementation of swap. I'm not sure if you are allowed to swap arrays. The swap of hours should work, but the other two might need extra effort.

    If you had used strings and vectors then it would probably work correctly.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I'm not sure if you are allowed to swap arrays.
    You're not, since swap works on types that have normal copying semantics, and arrays are not copyable.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. array of structs initialization - PLZ help...
    By Vanya in forum C++ Programming
    Replies: 2
    Last Post: 12-11-2002, 08:10 PM
  2. Creating 2D arrays on heap
    By sundeeptuteja in forum C++ Programming
    Replies: 6
    Last Post: 08-16-2002, 11:44 AM
  3. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  4. Basic Array Initialization in C
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 02-18-2002, 06:41 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM