C++ code help?

Alright I'm just starting this programming class and I'm not sure where I messed up on this code. Any help on getting it to build correctly would be appreciated!

PHP:
# include <iostream>
# include <iomanip>
# include <string>

using namespace std;
void ()
{
	// variables
	string weeklySales = "";
	const double commission = 0.07;
	const double fedTaxRate = 0.18;
    const double retirmentContribution = 0.10;
	const double socialSecurityAmount = 0.06;
	double grossWage = 0;
	double fedTax = 0;
	double retirement = 0;
	double socialSecurity = 0;
	double netWage = 0;
	// gather input
	<< "What was your weekly sales?   ";
	getline(cin, weeklySales);
	cin >> weeklySales;
	// calculations
	grossWage = weeklySales * commission;
	fedTax = grossWage * fedTaxRate;
	retirement = grossWage * retirmentContribution;
	socialSecurity = grossWage * socialSecurityAmount;
	netWage = grossWage - fedTax - retirment - socialSecurity;
	// output
	cout << endl << endl;
	cout << "Enter Total Sales:     " << setw(12) << weeklySales << endl;
	cout << "Total Sales:           " << setw(12) << weeklySales << endl;
	cout << "Gross Pay:             " << setw(12) << grossWage << endl;
	cout << setprecision(2) << fixed;
	cout << "Federal tax paid:      " << setw(12) << fedTax << endl;
	cout << "Social security paid:  " << setw(12) << socialSecurity << endl;
	cout << "Retirment Contribution:" << setw(12) << retirment << endl;
	cout << "Total deductions:      " << setw(12) << fedTax + retirement + socialSecurity << endl;
	cout << "Take home pay:         " << setw(12) << endl;
	system("pause");
}

I'm getting the following errors when I try and build this:

1>Lab1C.cpp(15): error C2059: syntax error : ')'
1>Lab1C.cpp(16): error C2143: syntax error : missing ';' before '{'
1>Lab1C.cpp(16): error C2447: '{' : missing function header (old-style formal list?)
1>
1>Build FAILED.
 
Code:
// gather input 
    << "What was your weekly sales?   ";

Missing a cout? :)

Thanks for pointing that out! I'm still returning the following errors when I add that cout line in:

1>Lab1C.cpp(15): error C2059: syntax error : ')'
1>Lab1C.cpp(16): error C2143: syntax error : missing ';' before '{'
1>Lab1C.cpp(16): error C2447: '{' : missing function header (old-style formal list?)
 
This may sound very daft, im only a beginner, but i cant see the main() function, dont you have to use one of these?
 
This may sound very daft, im only a beginner, but i cant see the main() function, dont you have to use one of these?

I agree with you too. Can't see main function. I will also suggest that you take a look at this line:

getline(cin, weeklySales);
 
Thanks for the input guys and you were correct about the main () function. I ended up getting that working correctly but couldn't figure out how to convert a string to a double so the code as I wrote above was useless. I ended up getting everything working correctly by modding my code some and removing the string :)

PHP:
# include <iostream> // header file
# include <iomanip> // allows for output to be formatted

using namespace std; // defines the library used
void main()
{
// identifying variables for the program
double weeklySales = 0; double grossPay = 0; double fedTax = 0; double socSecurity = 0;
double retirement = 0; double totDeductions = 0; double takeHomePay = 0;
// input which prompts user to enter their sales
cout << "What was your weekly sales?   ";
cin >> weeklySales; // user enters their weekly sale value so the calculations can begin
// calculations that are used to determine gross pay, fed tax paid, retirment contribution, total deductions and take home pay
grossPay = weeklySales * .07; fedTax = grossPay * .18; socSecurity = grossPay * .06; retirement = grossPay * .1; 
totDeductions = fedTax + socSecurity + retirement; takeHomePay = grossPay - totDeductions; 
cout << fixed << setprecision (2); // configures all items to end in 2 decimal place form
cout << "Total Sales:                          " << setw(8) << weeklySales << endl; // output is formatted so everything lines up, set width to 8 making sure everything is aligned
cout << "Gross Pay:                            " << setw(8) << grossPay << endl;
cout << "Federal tax paid:                     " << setw(8) << fedTax << endl;
cout << "Social Security paid:                 " << setw(8) << socSecurity << endl;
cout << "Retirment contribution                " << setw(8) << retirement << endl;
cout << "Total deductions:                     " << setw(8) << totDeductions << endl;
cout << "Take home pay:                        " << setw(8) << takeHomePay << endl;
system("pause");
}
 
Back
Top Bottom