Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

constants

Posted on 2000-04-09
9
Medium Priority
?
331 Views
Last Modified: 2010-04-02
can someone help me understand constants please. Here is my program i'm writing, but it's not working the deductions right.  
      char lastName[10];  
      char firstName[10];  
      float hoursWorked;
      double grossPay =0;
      double rate;
      const double sTax    = .075;
      const double fTax    = .15;
      const double miscDed = .20;
      double netIncome;
      double deduction;

//Calculate pay and deductions
      grossPay = hoursWorked * rate;
      deduction = (sTax + fTax + miscDed);
      netIncome = grossPay * deduction;

thanks,
nationnon

0
Comment
Question by:nationnon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 2

Expert Comment

by:homer99
ID: 2698942
what kind of output are you getting
0
 
LVL 1

Author Comment

by:nationnon
ID: 2698987
Enter your last name: r
Enter your first name: r
Enter hours worked: 40
Enter pay rate: 10
r r's gross pay was 400 but after deductions pay is now 170

Press any key to continue

0
 
LVL 1

Author Comment

by:nationnon
ID: 2698991
that's not the right deduction
are the constants right?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Expert Comment

by:homer99
ID: 2699075
nationnon:
your constants are fine.  your code is also fine except the last line. I believe it should read:
netIncome=netIncome - netIncome * deduction.
Give this a try.
0
 
LVL 2

Expert Comment

by:homer99
ID: 2699078
correction: netIncome = grossPay - grossPay * deduction;
sorry about that.
0
 

Expert Comment

by:kishore_joshi
ID: 2699470
Hi,
I think u need to use the following formula,


deduction = (sTax + fTax + miscDed)*rate * hoursWorked ;
netIncome = grossPay - deduction;


Thats it....

0
 
LVL 22

Expert Comment

by:nietod
ID: 2700241
True, but the other problem is that sTax and fTax are holding the tax _percents_ not the tax themselves.

Use an exampel to help you.  If you are in the 10% bracket (I wish) and you earn $100 (okay I don't wish) your tax should be $10 and you net shoudl be $90.

So

Tax = TaxPercent*Gross;
Net = Gross-Tax;
0
 
LVL 22

Accepted Solution

by:
nietod earned 160 total points
ID: 2700275
double grossPay =0;
double rate;
const double sTaxPct    = .075;
const double fTaxPct    = .15;
const double miscDedPct = .20;
double sTaxAmt ;
double fTaxAmt;
double miscDedAmt;

double netIncome;
double deduction;

//Calculate pay and deductions
grossPay = hoursWorked * rate;
sTaxAmt = sTaxPct*grossPay;
fTaxAmt = fTaxPct*grossPay;
miscDedAmt = miscDedPct*grossPay;

deduction = (sTaxAmt + fTaxAmt + miscDedAmt);
netIncome = grossPay - deduction;

(Technically your original

netIncome = grossPay * deduction;

was close, but it was calculatign the total deduction amount, not the net amount.  It should have been

netIncome = grossPay * (1-deduction);

but the method I give above is better when you have to start considering rounding to cents.)
0
 
LVL 2

Expert Comment

by:homer99
ID: 2701126
kishore joshi:
you just stated my answer in a different form.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question