Page 1 of 212> Show 40 post(s) from this thread on one page

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Solving for percentage Rates. (http://www.go4expert.com/forums/solving-percentage-rates-t18272/)

 Prof. Krauf 1Jul2009 07:03

Solving for percentage Rates.

I'm attempting a code here. I'm still a little scrappy and I'm not quite sure what I should be using here. I'm trying to create a code where the user inputs a name for an employee and a sales rate. Each employee gets payed 2,500 monthly, but Based on the sales rate they should find out their commission rate and it's dependent on this.
\$0.01–\$5,000 8 percent
\$5,000.01–\$10,000 10 percent
\$10,000.01 and above 12 percent

I just need a little help here I think I need a case or switch statement, but I'm not even sure where to begin or place the needed codes.

My code
Code:

```#include <iostream> #include <cstring> using namespace std; int main() { //declare variables char lastname[50]; int comission //get employee name cout << "Enter the Employee's last name: "; cin.getline (lastname, 50);  int salary = 2500 //get sales rate case '1' if commission 5000 < return 0; }```

Re: Solving for percentage Rates.

Quote:
 Originally Posted by Prof. Krauf (Post 50992) return 0;
What's that ??

For your question ... It's better to use nested Ifs than using Switch Case. Case checks for a particular value, but you need to check a range.

So, do it something like this :
Code: C

`..if( Salary > 10000 )      Commission = 12;else if( Salary > 5000 )      Commission = 10;else      Commission = 8;..`

 Prof. Krauf 2Jul2009 04:55

Re: Solving for percentage Rates.

Like this?

So it should be something like this?

Code: C

`#include <iostream>#include <cstring>using namespace std;int main(){      //declare variables      char lastname[50];      char firstname[50]      int comission;      //get employee name      cout << "Enter the Employee's first and last name last name: ";      cin >> getline (lastname, 50);      int salary = 2500;            //get sales rate      double commissionRate = 0.0;      if(commission <= 5000)            commisionRate  = 0.08;      else if(commission <= 10000 && commission > 5000)            commissionRate = 0.10;      else            commissionRate = 0.12;      cout << "firstname" << "lastname" << "commissionRate" <<      return 0;      system ("pause")}`

Re: Solving for percentage Rates.

Quote:
 Originally Posted by Prof. Krauf (Post 51003) oops didn't put in code tags correctly and I can't find the edit button.
No problem, I did it for you :)

As your post count is low, you cannot edit your posts. Keep posting and soon you will have edit button.

 Prof. Krauf 2Jul2009 06:53

Re: Solving for percentage Rates.

So should the code look like that? I think I need to add endline after the commissionRate.

Re: Solving for percentage Rates.

Quote:
 Originally Posted by Prof. Krauf (Post 51002) Like this? So it should be something like this? Code: C `#include #include using namespace std;int main(){      //declare variables      char lastname[50];      char firstname[50]      int comission;      //get employee name      cout << "Enter the Employee's first and last name last name: ";      cin >> getline (lastname, 50);      int salary = 2500;            //get sales rate      double commissionRate = 0.0;      if(commission <= 5000)            commisionRate  = 0.08;      else if(commission <= 10000 && commission > 5000)            commissionRate = 0.10;      else            commissionRate = 0.12;      cout << "firstname" << "lastname" << "commissionRate" <<      return 0;      system ("pause")}`
No !!! There are so many errors in your program. Let me highlight and explain :

Code:

```#include <iostream> #include <cstring> using namespace std; int main() {       //declare variables       char lastname[50];       char firstname[50]    // Missing ';'       int comission;       //get employee name       cout << "Enter the Employee's first and last name last name: ";       // you only get the lastname in this case !!       cin >> getline (lastname, 50);       int salary = 2500;             //get sales rate       double commissionRate = 0.0;       // You are using "commission" without assigning a value to it first !       if(commission <= 5000)             commisionRate  = 0.08;       else if(commission <= 10000 && commission > 5000)             commissionRate = 0.10;       else             commissionRate = 0.12;       // LOL, firstname, lastname etc.. should not be in quotes, 'cuz they are vars.       // And where is the ';' ??       cout << "firstname" << "lastname" << "commissionRate" <<       return 0;       // You are pausing after returning from main() !!       system ("pause")      // And where is ';' ?? }```

The correct program can be like this : (Run it and tell me if it's useful)
Code: C

`#include <iostream>#include <cstring>using namespace std;int main(){      //declare variables      char lastname[50];      char firstname[50];      double commissionRate;      int commission;      //get employee name      cout << "Enter the Employee's first and last name last name: ";      cin >> firstname >> lastname;      int salary = 2500;      //get sales rate      cout << "Please enter sales rate : ";      cin >> commission;      if(commission <= 5000)            commissionRate  = 0.08;      else if(commission <= 10000 && commission > 5000)            commissionRate = 0.10;      else            commissionRate = 0.12;      cout << "\nNAME = " << firstname << " " << lastname << "\nSALARY = " << salary;      cout << "\nSALES = " << commission << "\nCOMMISSION RATE = " << commissionRate;      getchar();      cout << "\n\nPress any key to exit ...\n";      getchar();      return 0;}`

NOTE that, I changed `system("pause")` to manual a pause, which has the benefit that it's not OS specific.

 naimish 2Jul2009 08:04

Re: Solving for percentage Rates.

Quote:
 Originally Posted by SaswatPadhi (Post 51006) No problem, I did it for you :) As your post count is low, you cannot edit your posts. Keep posting and soon you will have edit button.
What about having edit button for all post ;) ?

Re: Solving for percentage Rates.

Quote:
 Originally Posted by naimish (Post 51012) What about having edit button for all post ;) ?
That's true for the MODs (I'm one of 'em!).

 shabbir 2Jul2009 08:58

Re: Solving for percentage Rates.

Quote:
 Originally Posted by naimish (Post 51012) What about having edit button for all post ;) ?
Users cannot edit all posts because there is no point in allowing to edit some old threads / posts and also new members are not allowed for spam reasons.

Mods are exceptions.

 Prof. Krauf 9Jul2009 22:47

Re: Solving for percentage Rates.

All right I appreciate the help.

 All times are GMT +5.5. The time now is 00:11. Page 1 of 212> Show 40 post(s) from this thread on one page