Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Payroll problem

Name: Anonymous 2011-08-31 21:02

Hi

I'm trying to write a payroll program in C++. I used DevC as my compiler, but it's not the best, I know (Windows user). Gcc, MS Visual, and Geany don't do shit for me. So here's my code.

#include <cstdlib>
#include <iostream>
#include <iomanip>

using namespace std;

int main(int argc, char *argv[])

{
                //declaring variables
                double hoursWorked;
                double payRate;
                double regularPay = hoursWorked * payRate;
                double overtimePay = 1.5 * payRate * hoursWorked;
                double grossPay = regularPay + overtimePay;
                double stateTax;
                double federalTax;
                double totalTax = federalTax + stateTax;
                double unionDues;
                double netPay = grossPay - (totalTax + unionDues);

                char input;
               
                cout << "Enter total hours \n" << endl;
                cin >> hoursWorked;
                cout << "Enter rate of pay \n" << endl;
                cin >> payRate;
               
                if ( hoursWorked > 40 )
                   cout << "Gross pay = " << grossPay << 1.5 * payRate * hoursWorked;
                else if( hoursWorked <=40 )
                    cout << "\n\nGross pay = " << grossPay << hoursWorked * payRate;
                   
               
                //state tax section
               
                cout << "\n\nState taxation section \n" << endl;               
                cout << "Please enter gross pay \n" << endl;
               
                cin >> grossPay;
               
                if ( grossPay < 500 )//use if else statements
                   cout << "State Tax is 0 \n" << endl;
                else
                    if ( grossPay >= 500 && grossPay < 1000 )
                       cout << "State Tax is = " << grossPay * ( 3 / 100 ) << endl;
                    else
                        if ( grossPay >= 1000 )
                        cout << "State Tax is = " << grossPay * ( 5 / 100 ) << endl;
                       
                       
                system("PAUSE");
                return 0;
}

Everything runs fine until the taxation area. Right now the double ampersand is a syntax error, but I had it bracketed out to pass the compiler (per the book I'm reading) and it doesn't recognize that my whole taxation area is one large statement of if/else. It correctly says the tax is 0 for values less than 500, but at 501+ it doesn't say anything. I also tried the traditional way here:

//state tax section
                cout << "State Taxation Section. Please Enter Gross Pay. \n" << endl;

                if ( grossPay < 500 )//use if else statements
                   cout << stateTax = 0;
               
                else
                    if ( grossPay >= 500 )
                       { if ( grossPay < 1000 )
                       cout << stateTax = grossPay * ( 3 / 100 );
                       }

                    else
                        if ( grossPay >= 1000 )
                        cout << stateTax = grossPay * ( 5 / 100 );

Same issue. Wtf???

Name: Anonymous 2011-08-31 21:04

I also have tried putting the

if ( grossPay >= 500 && grossPay < 1000 ) part like this:
if ( grossPay >= 500 ) && ( grossPay < 1000 )

Name: Anonymous 2011-08-31 21:23

Back to /g/, please.

Name: Anonymous 2011-08-31 21:32

>>3
/g/ is for technology. this issue is a programming issue. i can see how a faggot such as yourself might confuse the two.

Name: Anonymous 2011-08-31 22:23

bump.

if this was an image board i'd post some boobies. text boards suck.

Name: Anonymous 2011-08-31 22:30

>>5-san, maybe you should go back to the imageboards where you belong!

Please?

Name: n3n7i 2011-08-31 22:53


//state tax section

    cout << "State Taxation Section. \n" << endl;
   
    stateTax = 0;
   
    //if ( grossPay < 500 ){
    //    cout << stateTax = 0;
    //    }
        // Don't need this

    if ( grossPay >= 500 ){

        if ( grossPay < 1000 ) stateTax = grossPay * ( 3 / 100 );

        if ( grossPay >= 1000 ) stateTax = grossPay * ( 5 / 100 );
        }
    }
    cout << stateTax;

Name: n3n7i 2011-08-31 23:13

*One too many }

    //state tax section
    cout << "State Taxation Section. \n" << endl;   
    stateTax = 0;

    if ( grossPay >= 500 ){

        if ( grossPay < 1000 ) stateTax = grossPay * ( 3 / 100 );
        if ( grossPay >= 1000 ) stateTax = grossPay * ( 5 / 100 );

        }

    cout << stateTax;

Name: Anonymous 2011-08-31 23:57

so i fixed my taxation (the text was wrong).

how do i define the result as stateTax?

Name: Anonymous 2011-09-01 0:22

Awesome code. Great size. Looks concise. Efficient. Elegant. Keep us all posted on your continued progress with any new code factoring or compiler optimization. Show us what you got man. Wanna see how freakin' expressive, efficient, concise and elegant you can get. Thanks for the motivation.

Name: Anonymous 2011-09-01 1:17

>>1
Sorry, man, this just isn't the place to talk about programming, especially beginner shit.  I know it seems like it should be, but it just isn't.  For beginner shit, try a usenet group like alt.comp.lang.learn.c-c++, I guess...  but really, you just have to suffer through it like everyone else did.  Google is your friend and I promise you that every question you have has already been asked 10 million times.

Name: Anonymous 2011-09-01 6:57

Here's a question for you: what is the value of 3 / 100? This may surprise you.

Furthermore,
double
Now you have two problems!

Name: BEEPER 2011-09-01 8:12

>>12
FU K YOU I USE ENTERPRISE BIGNUM LIBRARIES AND I AM NOT AFRAID OF ANYTHING

Name: Anonymous 2011-09-01 12:06

>>13
Well my l33t haskell lazy evaluation trumps your bignum libraries. You, along with your puny toy, will be crushed by the power of a real programming language.

Name: BEEPER 2011-09-01 12:38

>>14
I use clojure. Fuck your shit.

Name: Anonymous 2011-09-01 13:16

don't use doubles in conditions

Name: Anonymous 2011-09-01 13:36

Never use doubles

FTFY

Name: Anonymous 2011-09-01 13:44

The next post is doubles!

Name: Anonymous 2011-09-01 14:10

>>18
The previous post is dildos.

Don't change these.
Name: Email:
Entire Thread Thread List