Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 01-08-2011, 04:51 PM   #1
Fully Optimized
 
Join Date: Nov 2006
Posts: 3,629
Send a message via AIM to ߧ∩H♠H䎀
Default 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 Code:
# 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(cinweeklySales);
    
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.
__________________

ߧ∩H♠H䎀 is offline   Reply With Quote
Old 01-08-2011, 06:09 PM   #2
Site Team
 
berry120's Avatar
 
Join Date: Jul 2009
Location: England, UK
Posts: 3,425
Default Re: C++ code help?

Code:
// gather input 
    << "What was your weekly sales?   ";
Missing a cout?
__________________

__________________
Save the whales, feed the hungry, free the mallocs.
berry120 is offline   Reply With Quote
Old 01-08-2011, 06:40 PM   #3
Fully Optimized
 
Join Date: Nov 2006
Posts: 3,629
Send a message via AIM to ߧ∩H♠H䎀
Default Re: C++ code help?

Quote:
Originally Posted by berry120 View Post
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?)
ߧ∩H♠H䎀 is offline   Reply With Quote
Old 01-08-2011, 09:06 PM   #4
In Runtime
 
Join Date: Sep 2010
Posts: 240
Default Re: C++ code help?

This may sound very daft, im only a beginner, but i cant see the main() function, dont you have to use one of these?
TP-Oreilly is offline   Reply With Quote
Old 01-09-2011, 04:43 AM   #5
Solid State Member
 
unleasher's Avatar
 
Join Date: Jul 2004
Posts: 15
Send a message via Yahoo to unleasher
Default Re: C++ code help?

Quote:
Originally Posted by TP-Oreilly View Post
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);
unleasher is offline   Reply With Quote
Old 01-09-2011, 03:00 PM   #6
Fully Optimized
 
Join Date: Nov 2006
Posts: 3,629
Send a message via AIM to ߧ∩H♠H䎀
Default Re: C++ code help?

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 Code:
# 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 0double grossPay 0double fedTax 0double socSecurity 0;
double retirement 0double totDeductions 0double 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 .07fedTax grossPay .18socSecurity grossPay .06retirement grossPay .1
totDeductions fedTax socSecurity retirementtakeHomePay 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");

__________________

ߧ∩H♠H䎀 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 04:24 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0