Solving for percentage Rates.

Go4Expert Member
1Jul2009,07:03   #1
Prof. Krauf's Avatar
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;
}
~ Б0ЯИ Τ0 С0δЭ ~
1Jul2009,23:24   #2
SaswatPadhi's Avatar
Quote:
Originally Posted by Prof. Krauf View Post
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;
.
.
Go4Expert Member
2Jul2009,04:55   #3
Prof. Krauf's Avatar
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")
}

Last edited by SaswatPadhi; 2Jul2009 at 06:46.. Reason: Code-Blocks
~ Б0ЯИ Τ0 С0δЭ ~
2Jul2009,06:42   #4
SaswatPadhi's Avatar
Quote:
Originally Posted by Prof. Krauf View Post
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.
Go4Expert Member
2Jul2009,06:53   #5
Prof. Krauf's Avatar
So should the code look like that? I think I need to add endline after the commissionRate.
~ Б0ЯИ Τ0 С0δЭ ~
2Jul2009,07:07   #6
SaswatPadhi's Avatar
Quote:
Originally Posted by Prof. Krauf View Post
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")
}
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.

Last edited by SaswatPadhi; 2Jul2009 at 07:10..
Banned
2Jul2009,08:04   #7
naimish's Avatar
Quote:
Originally Posted by SaswatPadhi View Post
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 ?
~ Б0ЯИ Τ0 С0δЭ ~
2Jul2009,08:16   #8
SaswatPadhi's Avatar
Quote:
Originally Posted by naimish View Post
What about having edit button for all post ?
That's true for the MODs (I'm one of 'em!).
Go4Expert Founder
2Jul2009,08:58   #9
shabbir's Avatar
Quote:
Originally Posted by naimish View Post
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.
Go4Expert Member
9Jul2009,22:47   #10
Prof. Krauf's Avatar
All right I appreciate the help.