943,832 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 439
  • C++ RSS
Nov 13th, 2008
0

Help Required with Salary Program..

Expand Post »
Hi,

I was coding the following program..
// Program takes work hours and rate per hour and gives total
// salary after tax, if work hours are over 40, its increased by 1.5x.

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
	double hr_work, hr_rate, taxed_total, total;

	cout <<"Enter Hours Worked (Zero to Quit): ";
	cin >> hr_work;
	cout <<"\nEnter Hourly Rate: ";
	cin >> hr_rate;

	while(hr_work>0 && hr_rate>0){

		total = hr_work*hr_rate;
		taxed_total = total - (0.18 * total);
		cout <<"\nGross Wage = "<<total;
		cout <<"\nGross Wage after Tax Deduction = "<<taxed_total;
	
   		cout <<"\n\n---------------------------------\nEnter Hours Worked (Zero to Quit): ";
		cin >> hr_work;
		cout <<"\nEnter Hourly Rate: ";
		cin >> hr_rate;
	}	 
	 			
	getch();
	return 0;
}

Now how do i make the program do the following:

If the the number Hour entered it :

45 , then the following should happen:
40 + (5 x 1.5) = 47.5
and that 47.5 should be then multiplied with hourly rate and so on..

so any help is appreciated
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Evil Genius is offline Offline
11 posts
since Nov 2008
Nov 13th, 2008
0

Re: Help Required with Salary Program..

That's not really hard if I understand your (rather vague) requirements correctly.

- take in a number
- if it's bigger then 40: subtract 40 and store the rest
- multiply the rest with 1,5 and add to 40
- multiply the outcome with hourly rate
- done

[edit]
ps. One free piece advice: Stop using the conio.h header. It's outdated and was never standard c++ to start with. I know you think you need it for getch, but if you replace getch() with:
C++ Syntax (Toggle Plain Text)
  1. cin.ignore();
  2. cin.get();

You'll have the same result in standard C++
Last edited by Nick Evan; Nov 13th, 2008 at 8:49 am.
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Nov 13th, 2008
0

Re: Help Required with Salary Program..

Thanks a lot mate!

I was so messed up with the assignments didn't really think about it.

Thanks again and for the advice too
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Evil Genius is offline Offline
11 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Why does this work?
Next Thread in C++ Forum Timeline: please HELP ME!!!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC