Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 10-06-2006, 07:56 PM   #1 (permalink)
krisl100
krisl100
 
Join Date: Oct 2006
Location: Montreal
Posts: 34
krisl100 is on a distinguished road
need help with program

I am currently learning C++ on my own, I bought various books, now I found some excercises that I am trying to do, here is one of them:

Write a program to calculate a salesperson's net pay for a month & print a budget report based on given allocations. Our salespeople receive a base salary of $900.00 per month. Once their sales total reaches $200.00 they also receive a 6% commission. But only on the amount of sales above the $200.00 mark. For example: for a sales total of $1200.00 they would receive $60.00 commission; 6% of $1000.00. Their gross pay would be $960.00 (base salary of $900.00 + commission of $60.00.) Note that if the $200.00 level is not reached, the commission is $0.00, not negative.

From their gross pay, they must deduct 18% for taxes & other fees before allocating the remainder to their budget, as shown below.

INPUT: Prompt for first name & last name & monthly sales total

PROCESS: gross pay = base salary + commission
net pay = gross pay - deductions (18% of gross pay)

Allocate the remainder as follows:

Housing = 30% of net pay
Food & Clothing = 15% of net pay
Entertainment = 50% of net pay
Miscellaneous = 5% of net pay

So, that is what I am trying to do, I have gotten some ways here is my code so far:


Code:
#include "string"
#include "iostream"
#include "conio.h"
using namespace std;


int main()
{
	string fname, lname;

	const double base = 900.00;

	double sales, pay, com;

	cout << "Enter your fist name: ";
	cin >> fname;
	cout << "Enter your last name: ";
	cin >> lname;
	cout << "Enter your monthly sales total: ";
	cin >> sales;
	

	com = 0.06 * 1000.0;
	
	if (sales > 200.00)
		pay = base + com;
        
        
	else 


		
	
	cout << "base\n "  << base << endl;
	cout << "sales\n " << sales << endl;
	cout << "commission\n " << com << endl;
	cout << "pay\n " << pay << endl;

	getch();
	
	
	
	return 0;
}
I am having trouble with the clculations, & getting the percentage of commission to work properly. Any help would be great.

Last edited by redhead; 10-07-2006 at 01:19 AM.
krisl100 is offline   Reply With Quote
Old 10-07-2006, 01:59 AM   #2 (permalink)
redhead
Super Moderator
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,879
redhead is on a distinguished road
Quote:
Originally Posted by krisl100
Code:
#include "string"
#include "iostream"
#include "conio.h"
What is this part for?? You are trying to use system provided includes, so you need to address them as such ie
Code:
#include <string>
#include <iostream>
And why are you including conio.h ?? I see no part of your code in need of that, unless you're on a windows box, and you feel strongly attached to getch() there are ways to come around a halt in your program, without calling a system specific function.

Next thing is, you have declared the first name and last name of type strings, and you use the std::cin class representation of reading into string types, I would suggest to use the std::string::getline() in case someone decides to enter a <space> in their input.

If you were to move the com calculation inside your
Code:
if (sales > 200.00)
then you would be in better shape, and not have to refere to your hardcoded $1000.00 value, as I suspect this shoudl be the actual sale value..
For your description of it, the if() part would be more suited to look somethign like:
Code:
...
double sales, pay, com(0.0);
...
if(sales > 200)
  com = (sales - 200.00) * 0.06;
pay = base + com;
...
you see, in your declaring of the com variable you already assing it the least possible value, ie $0.00, so you only have to calculate it, if the sales is above your $200.00 limit.
When you want to calculate your net pay you can use the simple percentage rules, to calculate it like:
Code:
...
double net;
...
net = pay*0.82; /* gross pay - 18% */
...
And from there on, I belive it should be fairly easy to calculate the housing, food & clothing, entertainment, and miscellaneous..

Have fun with it, and try not to get cought up in a simple problem, think of it as learning a different language, if you dont quite know the words for what you're going to say, find others that eventualy will describe the same thing, and hopefully provide a solution which gives teh same result as expected.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
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 On


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with copying backwards rogue Standard C, C++ 9 04-24-2005 04:39 PM
C++ Deadlock Detection Program Help... coolsc81 Standard C, C++ 2 10-26-2004 06:14 AM
Help on starting new program B00tleg Standard C, C++ 21 10-17-2004 12:58 PM


All times are GMT -8. The time now is 10:20 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting