# C++ calculating percentage



## fuentes (Nov 18, 2008)

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!!!


----------



## JimmySeal (Sep 25, 2007)

if (totalms > 200 ) 
{ 
*comm = (totalms - 200) * 0.06; *
}
else
{ 
(totalms <= 200 );
comm = 0;
}

The problem was the line in bold, which I've fixed. The line in red does nothing and shouldn't be there.

And just for your information, dollar amounts are written with the dollar sign before the number like this: $200, not like this: 200$.


----------



## fuentes (Nov 18, 2008)

hey thanks for the reply!!!
i got it to work yesterday but i appreciate your help & method, it wokrs as well

yea i know its $200 and not 200$ hehe but when i write fast i tend to do that since i speak more french than english

thanks again!


----------

