C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 22nd, 2009, 09:57 AM
fuentes fuentes is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 6 fuentes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 50 m 9 sec
Reputation Power: 0
Exclamation General - C++ calculating percentage

hello guys
i am new to c++ and we just had our first assignment.
Everything in my program works except that i didnt do one calculations right which leads to having wrong answers everywhere.

If someones amount of sales is higher that 200 THEN they will receive a 6% commission. For example they have an amount of sales of 1200$, they will receive 60$, 6% of 1000, since the last 200$ isnt higher than 200$.
because right now when i enter 1200, i get 72$ of commision and it calculates the last 200$.

im pretty sure its my if statement thats wrong... but i dont know what to do here. heres my code.


/*----------------------------------------------------------------------------------
Source file: mainsource.cpp
Author: ---
Compiler: Bloodshed Dev-C++ 4.9.9.2
Purpose: Program to calculate a salesperson's net pay for a month and print a budget
report based on given allocations.
-----------------------------------------------------------------------------------*/

#include <iostream>
using namespace std;

int main ()
{
string fname, lname;
double totalms, npay, gpay, deduct, comm = 0, house, foodc, entert, misc;
const int basepay = 900;

// End user inputs his first name, last name and total monthly sales.

cout << endl << "Please enter your first name (with no spaces): ";
cin >> fname;
cout << endl << "Please enter your last name (with no spaces): ";
cin >> lname;
cout << endl << "Please enter your total monthly sales: $";
cin >> totalms;

// Perform calculations for budget report.

if (totalms > 200 )
{
comm = (totalms/100) * 6;
}
else
{
(totalms <= 200 );
comm = 0;
}

gpay = basepay + comm;
deduct = (gpay/100) * 18;
npay = gpay - deduct;

// Perform calculations for budget allocation.

house = (npay/100) * 30;
foodc = (npay/100) * 15;
entert = (npay/100) * 50;
misc = (npay/100) * 5;

// Result displayed on a table format.

cout << endl << endl << endl << "BUDGET REPORT FOR: " << fname << " " << lname << endl << endl;
cout << "Base Pay Sales Commission Gross Pay Deductions" << endl;
cout << " 900 " << " " << totalms << " " << comm << " " << gpay << " " << deduct << endl << endl;
cout << "Net pay: $" << npay << endl << endl;
cout << "BUDGET ALLOCATIONS:" << endl;
cout << "Housing = " << house << endl;
cout << "Food/Clothing = " << foodc << endl;
cout << "Entertainment = " << entert << endl;
cout << "Miscellaneous = " << misc << endl;

cout << "\n \nPlease press the key 'enter' to end the program!";
cin.ignore(2);

return 0;
}



thanks!!!

Reply With Quote
  #2  
Old January 22nd, 2009, 10:38 AM
C++101 C++101 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 136 C++101 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 3 h 16 m 6 sec
Reputation Power: 6
So let me get this straight you are only doing it on every $1000? Because then all you have to do is divide total by 1000 then mult by .06.

Or if you are doing it by every transaction > 200 then you grab the interest right after the amount is entered then store it in a variable that holds the interest amount.

Reply With Quote
  #3  
Old January 22nd, 2009, 10:48 AM
fuentes fuentes is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 6 fuentes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 50 m 9 sec
Reputation Power: 0
i changed my code to this

if (totalms > 200 )
{
comm = ((totalms-200)/100) * 6;
;
}
else
{
comm = 0;
}


its not quite that but its getting there.

its not every 1000. they get commission of 6% every time they reach above 200$. but this happend every 200$.
so they will get commission at 201$
not at 275$.
they will get commission at 401$
etc....

Reply With Quote
  #4  
Old January 22nd, 2009, 10:55 AM
fuentes fuentes is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 6 fuentes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 50 m 9 sec
Reputation Power: 0
oh i put a random semicolon before that wasnt in my code

Reply With Quote
  #5  
Old January 22nd, 2009, 10:59 AM
C++101 C++101 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 136 C++101 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 3 h 16 m 6 sec
Reputation Power: 6
Why at 201 but not at 275? Makes no sense. 275 > 200.

Could you post the lab directions? That might help me understand what your trying to say.

Reply With Quote
  #6  
Old January 22nd, 2009, 11:13 AM
fuentes fuentes is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 6 fuentes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 50 m 9 sec
Reputation Power: 0
Program 2: Write a program to calculate a salesperson's net pay for a month and print a budget report based on given allocations. Our salespeople receive a base salary of $900.00 per month. Once their sales reach $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 (you will learn how to do this in class #2, but it will not require radical changes).

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

INPUT: Prompt for the salesperson's first name and last name (assume there will be no spaces) and monthly sales total.

PROCESS: Gross pay = base salary + commission (as stated above)
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

OUTPUT: Display a report formatted as shown below. (Don't worry if the numbers donít align or you donít get a consistent number of decimal places, but otherwise follow the given format. please turn over)

Reply With Quote
  #7  
Old January 22nd, 2009, 11:35 AM
fuentes fuentes is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 6 fuentes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 50 m 9 sec
Reputation Power: 0
changed the code to this
almost there
but not quite this

if (totalms > 200) {
if((totalms%200)==0) {
comm = ((totalms-200)/100) * 6;
}
else {
comm = ((totalms-100)/100) * 6;
}
}
else
{
comm = 0;
}

and at the top totalms is int, not double.

Reply With Quote
  #8  
Old January 22nd, 2009, 01:18 PM
C++101 C++101 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 136 C++101 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 3 h 16 m 6 sec
Reputation Power: 6
I got it now to they make 6% on every dollar above the $200 mark so they will get it at $275 but only 6% of $75 so all you have to do is check if the sales is > 200 if so temp = (sales - 200) * .06; That will give you the commish. And then you probably can figure the rest out. Let me know if you need more help.

Reply With Quote
  #9  
Old January 22nd, 2009, 01:20 PM
fuentes fuentes is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 6 fuentes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 50 m 9 sec
Reputation Power: 0
nooo no its ok i got it to work

the teacher also wanted to make it work with decimals so no int only double. it looks like this and works fine!

/*----------------------------------------------------------------------------------
Source file: mainsource.cpp
Author: ----
Compiler: Bloodshed Dev-C++ 4.9.9.2
Purpose: Program to calculate a salesperson's net pay for a month and print a budget
report based on given allocations.
-----------------------------------------------------------------------------------*/

#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int main ()
{
string fname, lname;
double totalms, npay, gpay, deduct, comm = 0, house, foodc, entert, misc;
const int basepay = 900;

// End user inputs his first name, last name and total monthly sales.

cout << endl << "Please enter your first name (with no spaces): ";
cin >> fname;
cout << endl << "Please enter your last name (with no spaces): ";
cin >> lname;
cout << endl << "Please enter your total monthly sales: $";
cin >> totalms;

// Perform calculations for budget report.

if (totalms > 200) {
if((fmod(totalms,200))==0) {
comm = ((totalms-200)/100) * 6;
}
else {
comm = floor(totalms/200) * 12;
}
}
else
{
comm = 0;
}

gpay = basepay + comm;
deduct = gpay * .18;
npay = gpay - deduct;

// Perform calculations for budget allocation.

house = npay * .30;
foodc = npay * .15;
entert = npay * .50;
misc = npay * .05;

// Result displayed on a table format.

cout << endl << endl << endl << "BUDGET REPORT FOR: " << fname << " " << lname << endl << endl;
cout << "Base Pay Sales Commission Gross Pay Deductions" << endl;
cout << " 900 " << " " << totalms << " " << comm << " " << gpay << " " << deduct << endl << endl;
cout << "Net pay: $" << npay << endl << endl;
cout << "BUDGET ALLOCATIONS:" << endl;
cout << "Housing = " << house << endl;
cout << "Food/Clothing = " << foodc << endl;
cout << "Entertainment = " << entert << endl;
cout << "Miscellaneous = " << misc << endl;

cout << "\n \nPlease press the key 'enter' to end the program!";
cin.ignore(2);

return 0;
}

Reply With Quote
  #10  
Old January 22nd, 2009, 01:27 PM
C++101 C++101 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 136 C++101 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 3 h 16 m 6 sec
Reputation Power: 6
cool yeah your doing exactly what I was saying. Congrats!!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > General - C++ calculating percentage


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap