Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Please help me =(


  • Please log in to reply
5 replies to this topic

#1 KelvinS

KelvinS

  • Members
  • 9 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:11:24 PM

Posted 01 May 2010 - 10:23 AM

Can anybody tell me what's wrong with the code?

I'm new on this >< I was trying to create a salary calculator by deducting tax , EPF , and insurance. But , the calculation result is weird =(

This is my coding.
[codebox]#include <iostream>
#include <conio.h>
#include <iomanip>

using namespace std;

void main ()

{

cout << "Enter employee's name: ";
char employeeName[50];
cin >> employeeName;
cout << "Enter gross salary amount: ";
double grossSalary;
cin >> grossSalary;
cout << "\n";
cout << setw(43) << setfill ('=') << "\n";
cout << "Name: " << employeeName << "\n";
cout << setw(43) << setfill ('-') << "\n";
cout << setw(31) <<"Gross ammount: ................" << " RM " << right <<grossSalary << "\n";
cout << "Deductions\n";
double incomeTax , EPF , healthInsurance , netPay ;
incomeTax = grossSalary * 7.5/100.0;
EPF = grossSalary * 5.85/100.0;
healthInsurance = 50;
netPay = grossSalary - ( incomeTax + EPF + healthInsurance );
cout << setprecision (2) << " Income tax: ............" << " RM " << right << incomeTax << "\n" ;
cout << setprecision (2) << " EPF: ..................." << " RM " << right << EPF << "\n";
cout << fixed << " Health Insurance: ......" << " RM " << right << healthInsurance << "\n";
cout << setw(43) << setfill ('-') << "\n";
cout << setw(30) << "Net pay: ......................" << " RM " << netPay << "\n" ;
cout << setw(43) << setfill ('=') << "\n";

getch();

}
[/codebox]

The Result of the income tax and EPF is RM 1.9e+003 and RM 1.5e+003.

please do help me =)

BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:09:24 AM

Posted 01 May 2010 - 10:37 AM

The easiest thing to do is to calculate deductions for a particular salary on paper. Then comment out all of your code that calculates the deductions except for one. Print out the result of that calculation to see if it is correct. If you are storing a value, print out that variable to make sure what you think is getting stored really is getting stored. Then check the next calculation, and do the same thing. You are missing something really obvious, and when you check your output the output of each calculation line by line, it will become obvious to you also. ;)

#3 KelvinS

KelvinS
  • Topic Starter

  • Members
  • 9 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:11:24 PM

Posted 01 May 2010 - 11:00 AM

Uh oh , I tried cout << incomeTax and the output is the output I want. Now I'm getting confused=.=

#4 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:09:24 AM

Posted 01 May 2010 - 01:12 PM

Then try the next calculation.

#5 KelvinS

KelvinS
  • Topic Starter

  • Members
  • 9 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:11:24 PM

Posted 01 May 2010 - 09:54 PM

All of the calculation is working and the result is just fine w/o the << setpricision(2). Hmmm what's actually the right solution =D?

#6 Romeo29

Romeo29

    Learning To Bleep


  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:10:24 AM

Posted 02 May 2010 - 11:35 AM

put fixed after setprecision like this:

cout << setprecision(2) << fixed << incomeTax;

Ask your teacher (or read in a book) about fixed and scientific.

Your code is not using latest C++ standards. The function main() must return int.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users