2 Replies - 261 Views - Last Post: 07 May 2019 - 01:47 AM Rate Topic: -----

#1 codeman501   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 06-May 19

I can not get pass this C++ syntax error. Any ideas?

Posted 07 May 2019 - 12:05 AM

#include 
#include 
#include 
#include 
#include 

using namespace std;

void pay_report(string, string, ifstream, string, char, float);
void check(string, string, double&);
void wkly_pay_roll(ofstream&, string, string, char, float, float, double&, double&, double&, double&);
float low_salary_deduction(float, float, double&, double&, double&, double&);
float high_salary_deduction(float, float, double&, double&, double&);
float low_hourly_deduction(float, float, double&, double&, double&, double&);
float high_hourly_deduction(float, float, double&, double&, double&);
int main()
{
        double state_tax = 0.03;
        double fed_tax = 0.08; 
        double ss_tax = 0.02;
        double net_pay = 0.00;
        ifstream infile;
        ofstream outfile;
        string filename = "PAYMASTER.DAT";
        string fname[10], lname[10];
        char pay_type[10];
        float pay_rate[10];
        float year_to_date_gross[10];
        int i = 0;
        int input;
        bool done = false;
        while(!done)
        {

                infile.open("PAYMASTER.dat");
                cout << "Please press enter choose from the following." << endl;
                getchar();
                system ("cls");
                cout << "1. Would you like to run a weekly pay roll? Press 1 for yes." << endl << endl;
                cout << "2. Would you like to print a pay rate/salary report? Press 2 for yes." << endl << endl;
                cout << "3. Exit the program press 3" << endl << endl;
                cin >> input;
                getchar();
                system ("cls");

                        switch(input)
                        {
                                case 1:
                                        outfile.open("test.dat");
                                                for(i = 0; i < 5; i++)
                                                        {
                                                                outfile << setprecision(2) << showpoint << fixed;
                                                                outfile << lname[i] << ',' << fname[i] << ' ' << pay_type[i] << ' ' << pay_rate[i] << ' ' << year_to_date_gross[i] << endl;
                                                                wkly_pay_roll(outfile, lname[i], fname[i], pay_type[i], pay_rate[i],year_to_date_gross[i], state_tax, fed_tax, ss_tax, net_pay);
                                                        }
                                                break;
                                case 2:
                                        for(i = 0; i < 5; i++)
                                        {
                                                pay_report(fname[i], lname[i], infile, filename, pay_type[i], pay_rate[i]);
                                        }
                                        break;
                                default:
                                        done = true;    
                                        cout << "You have exited." << endl;
                                                break;
                        }
        }
        if(!infile)
        {
                cout << "This is the inccorect file." << endl << endl;
                cout << "This is the location of the file: F:/Programming Foundations 1 CH 7/FINAL PROGRAM/FINAL PROGRAM." << endl;
                getchar();
                system ("cls");
        }
                for(i = 0; i < 5; i++)
                {
                        infile >> lname[i] >> fname[i] >> pay_type[i] >> pay_rate[i] >> year_to_date_gross[i];
                }

        /*outfile.open("test.dat");

        for(i = 0; i < 5; i++)
        {
                outfile << setprecision(2) << showpoint << fixed;
                //outfile << lname[i] << ',' << fname[i] << ' ' << pay_type[i] << ' ' << pay_rate[i] << ' ' << year_to_date_gross[i] << endl;
                wkly_pay_roll(outfile, lname[i], fname[i], pay_type[i], pay_rate[i],year_to_date_gross[i], state_tax, fed_tax, ss_tax, net_pay);
        }*/
        infile.close();
        outfile.close();
        return 0;
}
void wkly_pay_roll(ofstream &outfile, string lname, string fname, char pay_type, float pay_rate,  float year_to_date_gross, double& state_tax, double& fed_tax, double& ss_tax, double& net_pay)
{
        //float total_deduction = 0;
        char ans;
        int hours_worked, ot_hours, i;
        
        for(i = 0; i < 1; i++)
        {
                if(pay_type == 'H')
                {
                        cout << lname << ',' << fname << " is a hourly employee." << endl << endl;
                        cout << "Please enter the hours worked for this employee UP to 40 hours for this week." << endl << endl;
                        cin >> hours_worked;
                        year_to_date_gross = pay_rate * hours_worked;
                        cout << "Did this employee work overtime? If yes type y or n." <> ans;
                        getchar();
                        system("cls");
                                if(ans == 'y' || 'Y')
                                {
                                        cout << "Please enter the amount of overtime hours the employee worked." << endl << endl;
                                        cout << "Type 0 if employee did not work overtime hours." << endl;
                                        cin >> ot_hours;
                                        ot_hours = ot_hours *(pay_rate * 1.5);
                                        year_to_date_gross = year_to_date_gross + ot_hours;
                                                if(pay_rate < 30000)
                                                {
                                                        low_hourly_deduction(pay_rate, year_to_date_gross, state_tax, fed_tax, ss_tax, net_pay);
                                                }
                                                else if(pay_rate > 30000)
                                                {       
                                                        high_hourly_deduction(pay_rate, year_to_date_gross, state_tax, fed_tax, net_pay);
                                                }       
                                                else if(pay_type == 'S')
                                                {
                                                if(pay_rate < 30000)
                                                        low_salary_deduction(pay_rate, year_to_date_gross, state_tax, fed_tax, ss_tax, net_pay);
                                                
                                                else if(pay_rate > 30000)
                                                        high_salary_deduction(pay_rate, year_to_date_gross, state_tax, fed_tax, net_pay);
                                                        
                                                }
                                                outfile << lname << ' ' << fname << ' ' << pay_type << ' ' << ' ' << pay_rate << ' ' << year_to_date_gross << endl;
                                                check(fname, lname, net_pay);
                                                //total_deduction = year_to_date_gross - net_pay;
                                                cout << "Check is ready to print." << endl;
                                                getchar();
                                                system("pause");
                                                system("cls");
                                                outfile.close();
                        }       
                }
        }
}
float low_salary_deduction(float pay_rate, float year_to_date_gross, double& state_tax, double& fed_tax, double& ss_tax, double& net_pay)
{
        state_tax = state_tax * pay_rate;
        fed_tax = fed_tax * pay_rate;
        ss_tax = ss_tax * pay_rate;
        return net_pay = year_to_date_gross - state_tax - fed_tax - ss_tax;
}
float high_salary_deduction(float pay_rate, float year_to_date_gross, double& state_tax, double& fed_tax, double& net_pay)
{
        state_tax = state_tax * pay_rate;
        fed_tax = fed_tax * pay_rate;
        return net_pay = year_to_date_gross - state_tax - fed_tax;
}
float low_hourly_deduction(float pay_rate, float year_to_date_gross, double& state_tax, double& fed_tax, double& ss_tax, double& net_pay)
{
        state_tax = state_tax * pay_rate;
        fed_tax = fed_tax * pay_rate;
        ss_tax = ss_tax * pay_rate;
        return net_pay = year_to_date_gross - state_tax - fed_tax - ss_tax;
}
float high_hourly_deduction(float pay_rate, float year_to_date_gross, double& state_tax, double& fed_tax, double& net_pay)
{
        state_tax = state_tax * pay_rate;
        fed_tax = fed_tax * pay_rate;
        return net_pay = year_to_date_gross - state_tax - fed_tax;
}
void check(string fname, string lname, double& net_pay)
{
        ofstream fout;
        string date;
        int cents;
        int dollars = (int) net_pay;
        cents = (int)((net_pay - dollars) * 100);
        for(int i = 0; i < 1; i++)
        {
                fout.open(lname.c_str());
                cout << "Type in the date. (m/d/yyyy)" << endl;
                cin >> date;
                cout << setprecision(2) << showpoint << fixed;
                fout << "12432 Somewhere St." << endl;
                fout << setw(12) << left << setfill(' ') << "Russellville, AR 72802" << setw(12) << right << setfill('_') << date << setw(8) << right << setfill('_') << "Date" << endl;
                fout << endl << endl;
                fout << setw(7) << left << setfill('_') << "Pay" << setw(50) << left << setfill('_') << fname << ' ' << lname <<  "   $" << setw(15) << right << setfill('_') << net_pay <<  endl;
                fout << endl << endl;
                fout << setw(10) << left << setfill('_') << dollars << "_Dollars_&_" << setw(10) << left << setw(10) << right << cents <<  " Cents" << endl;
                fout << endl << endl;
                fout << setw(10) << right << setfill('_') << left << "Bank of Foundations I" ; 
                fout << endl << endl << endl;
                fout.close();

        }
}
void pay_report(string fname, string lname, ifstream infile, string filename, char pay_type, float pay_rate)
{
                infile.open(filename.c_str());
                float trash;
                cout << setprecision(2) << showpoint << fixed;
                infile >> lname >> fname >> pay_type >> pay_rate >> trash;
                cout << "Employee's Name" << setw(6)<< right << setfill(' ') << "Employee's Pay Type" << setw(6) << right << setfill(' ') << "Employee's pay rate" << endl << endl;
                cout << fname << ' ' << lname << setw(6)<< right << setfill(' ') << pay_type << setw(6)<< right << setfill(' ') << pay_rate << endl << endl;
                infile.close();
}


This post has been edited by Skydiver: 07 May 2019 - 05:50 PM
Reason for edit:: Put code in code tags. Learn to do this yourself.


Is This A Good Question/Topic? 0
  • +

Replies To: I can not get pass this C++ syntax error. Any ideas?

#2 codeman501   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 06-May 19

Re: I can not get pass this C++ syntax error. Any ideas?

Posted 07 May 2019 - 12:18 AM

error main.cpp: In function ‘int main()’:
main.cpp:61:80: error: use of deleted function ‘std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const std::basic_ifstream<_CharT, _Traits>&) [with _CharT = char; _Traits = std::char_traits]’
pay_report(fname[i], lname[i], infile, filename, pay_type[i], pay_rate[i]);
^
In file included from main.cpp:3:0:
/usr/include/c++/5/fstream:519:7: note: declared here
basic_ifstream(const basic_ifstream&) = delete;
^
main.cpp:10:6: note: initializing argument 3 of ‘void pay_report(std::string, std::string, std::ifstream, std::string, char, float)’
void pay_report(string, string, ifstream, string, char, float);
^
Was This Post Helpful? 0
  • +
  • -

#3 codeman501   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 06-May 19

Re: I can not get pass this C++ syntax error. Any ideas?

Posted 07 May 2019 - 01:47 AM

I finally got it out
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <conio.h>
#include <fstream>

using namespace std;

void readFile(char [][30], ifstream&);
void pay_report(string, string, ifstream, string, char, float);
void check(string, string, double&);
void wkly_pay_roll(ofstream&, string, string, char, float, float, double&, double&, double&, double&);
float low_salary_deduction(float, float, double&, double&, double&, double&);
float high_salary_deduction(float, float, double&, double&, double&);
float low_hourly_deduction(float, float, double&, double&, double&, double&);
float high_hourly_deduction(float, float, double&, double&, double&);
int main()
{
	double state_tax = 0.03;
	double fed_tax = 0.08; 
	double ss_tax = 0.02;
	double net_pay = 0.00;
	ifstream infile;
	ofstream outfile;
	string filename = "PAYMASTER.DAT";
	string fname[10], lname[10];
	char pay_type[10];
	float pay_rate[10];
	float year_to_date_gross[10];
	int i = 0;
	int input;
	bool done = false;
	while(!done)
	{

		infile.open("PAYMASTER.dat");
		cout << "Please press enter choose from the following." << endl;
		getchar();
		system ("cls");
		cout << "1. Would you like to run a weekly pay roll? Press 1 for yes." << endl << endl;
		cout << "2. Would you like to print a pay rate/salary report? Press 2 for yes." << endl << endl;
		cout << "3. Exit the program press 3" << endl << endl;
		cin >> input;
		getchar();
		system ("cls");


			switch(input)
			{
				case 1:
					outfile.open("test.dat");
						for(i = 0; i < 5; i++)
							{
								outfile << setprecision(2) << showpoint << fixed;
								outfile << lname[i] << ',' << fname[i] << ' ' << pay_type[i] << ' ' << pay_rate[i] << ' ' << year_to_date_gross[i] << endl;
								wkly_pay_roll(outfile, lname[i], fname[i], pay_type[i], pay_rate[i],year_to_date_gross[i], state_tax, fed_tax, ss_tax, net_pay);
							}
						break;
				case 2:
					for(i = 0; i < 5; i++)
					{
                void readFile(char pay_rate[][30], ifstream& inputFile);					}
					break;
				default:
					done = true;	
					cout << "You have exited." << endl;
						break;
			}
	}
	if(!infile)
	{
		cout << "This is the inccorect file." << endl << endl;
		cout << "This is the location of the file: F:/Programming Foundations 1 CH 7/FINAL PROGRAM/FINAL PROGRAM." << endl;
		getchar();
		system ("cls");
	}
		for(i = 0; i < 5; i++)
		{
			infile >> lname[i] >> fname[i] >> pay_type[i] >> pay_rate[i] >> year_to_date_gross[i];
		}

	/*outfile.open("test.dat");

	for(i = 0; i < 5; i++)
	{
		outfile << setprecision(2) << showpoint << fixed;
		//outfile << lname[i] << ',' << fname[i] << ' ' << pay_type[i] << ' ' << pay_rate[i] << ' ' << year_to_date_gross[i] << endl;
		wkly_pay_roll(outfile, lname[i], fname[i], pay_type[i], pay_rate[i],year_to_date_gross[i], state_tax, fed_tax, ss_tax, net_pay);
	}*/
	infile.close();
	outfile.close();
	return 0;
}
void wkly_pay_roll(ofstream &outfile, string lname, string fname, char pay_type, float pay_rate,  float year_to_date_gross, double& state_tax, double& fed_tax, double& ss_tax, double& net_pay)
{
	//float total_deduction = 0;
	char ans;
	int hours_worked, ot_hours, i;
	
	for(i = 0; i < 1; i++)
	{
		if(pay_type == 'H')
		{
			cout << lname << ',' << fname << " is a hourly employee." << endl << endl;
			cout << "Please enter the hours worked for this employee UP to 40 hours for this week." << endl << endl;
			cin >> hours_worked;
			year_to_date_gross = pay_rate * hours_worked;
			cout << "Did this employee work overtime? If yes type y or n." <<endl;
			cin >> ans;
			getchar();
			system("cls");
				if(ans == 'y' || 'Y')
				{
					cout << "Please enter the amount of overtime hours the employee worked." << endl << endl;
					cout << "Type 0 if employee did not work overtime hours." << endl;
					cin >> ot_hours;
					ot_hours = ot_hours *(pay_rate * 1.5);
					year_to_date_gross = year_to_date_gross + ot_hours;
						if(pay_rate < 30000)
						{
							low_hourly_deduction(pay_rate, year_to_date_gross, state_tax, fed_tax, ss_tax, net_pay);
						}
						else if(pay_rate > 30000)
						{	
							high_hourly_deduction(pay_rate, year_to_date_gross, state_tax, fed_tax, net_pay);
						}	
						else if(pay_type == 'S')
						{
						if(pay_rate < 30000)
							low_salary_deduction(pay_rate, year_to_date_gross, state_tax, fed_tax, ss_tax, net_pay);
						
						else if(pay_rate > 30000)
							high_salary_deduction(pay_rate, year_to_date_gross, state_tax, fed_tax, net_pay);
							
						}
						outfile << lname << ' ' << fname << ' ' << pay_type << ' ' << ' ' << pay_rate << ' ' << year_to_date_gross << endl;
						check(fname, lname, net_pay);
						//total_deduction = year_to_date_gross - net_pay;
						cout << "Check is ready to print." << endl;
						getchar();
						system("pause");
						system("cls");
						outfile.close();
			}	
		}
	}
}
float low_salary_deduction(float pay_rate, float year_to_date_gross, double& state_tax, double& fed_tax, double& ss_tax, double& net_pay)
{
	state_tax = state_tax * pay_rate;
	fed_tax = fed_tax * pay_rate;
	ss_tax = ss_tax * pay_rate;
	return net_pay = year_to_date_gross - state_tax - fed_tax - ss_tax;
}
float high_salary_deduction(float pay_rate, float year_to_date_gross, double& state_tax, double& fed_tax, double& net_pay)
{
	state_tax = state_tax * pay_rate;
	fed_tax = fed_tax * pay_rate;
	return net_pay = year_to_date_gross - state_tax - fed_tax;
}
float low_hourly_deduction(float pay_rate, float year_to_date_gross, double& state_tax, double& fed_tax, double& ss_tax, double& net_pay)
{
	state_tax = state_tax * pay_rate;
	fed_tax = fed_tax * pay_rate;
	ss_tax = ss_tax * pay_rate;
	return net_pay = year_to_date_gross - state_tax - fed_tax - ss_tax;
}
float high_hourly_deduction(float pay_rate, float year_to_date_gross, double& state_tax, double& fed_tax, double& net_pay)
{
	state_tax = state_tax * pay_rate;
	fed_tax = fed_tax * pay_rate;
	return net_pay = year_to_date_gross - state_tax - fed_tax;
}
void check(string fname, string lname, double& net_pay)
{
	ofstream fout;
	string date;
	int cents;
	int dollars = (int) net_pay;
	cents = (int)((net_pay - dollars) * 100);
	for(int i = 0; i < 1; i++)
	{
		fout.open(lname.c_str());
		cout << "Type in the date. (m/d/yyyy)" << endl;
		cin >> date;
		cout << setprecision(2) << showpoint << fixed;
		fout << "12432 Somewhere St." << endl;
		fout << setw(12) << left << setfill(' ') << "Russellville, AR 72802" << setw(12) << right << setfill('_') << date << setw(8) << right << setfill('_') << "Date" << endl;
		fout << endl << endl;
		fout << setw(7) << left << setfill('_') << "Pay" << setw(50) << left << setfill('_') << fname << ' ' << lname <<  "   $" << setw(15) << right << setfill('_') << net_pay <<  endl;
		fout << endl << endl;
		fout << setw(10) << left << setfill('_') << dollars << "_Dollars_&_" << setw(10) << left << setw(10) << right << cents <<  " Cents" << endl;
		fout << endl << endl;
		fout << setw(10) << right << setfill('_') << left << "Bank of Foundations I" ; 
		fout << endl << endl << endl;
		fout.close();

	}
}
void pay_report(string fname, string lname, ifstream infile, string filename, char pay_type, float pay_rate)
{
		infile.open(filename.c_str());
		float trash;
		cout << setprecision(2) << showpoint << fixed;
		infile >> lname >> fname >> pay_type >> pay_rate >> trash;
		cout << "Employee's Name" << setw(6)<< right << setfill(' ') << "Employee's Pay Type" << setw(6) << right << setfill(' ') << "Employee's pay rate" << endl << endl;
		cout << fname << ' ' << lname << setw(6)<< right << setfill(' ') << pay_type << setw(6)<< right << setfill(' ') << pay_rate << endl << endl;
		infile.close();
}


This post has been edited by Skydiver: 07 May 2019 - 05:49 PM
Reason for edit:: Removed unnecessary quote. Put code in code tags.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1