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. [FONT="]$0.01–$5,000 8 percent[/FONT] [FONT="]$5,000.01–$10,000 10 percent[/FONT] [FONT="]$10,000.01 and above 12 percent[/FONT] 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; }
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: . . if( Salary > 10000 ) Commission = 12; else if( Salary > 5000 ) Commission = 10; else Commission = 8; . .
Like this? So it should be something like this? Code: #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 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.
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] [COLOR="Red"][B]// Missing ';'[/B][/COLOR] int comission; //get employee name cout << "Enter the Employee's first and last name last name: "; [COLOR="Red"][B] // you only get the lastname in this case !![/B][/COLOR] cin >> getline (lastname, 50); int salary = 2500; //get sales rate double commissionRate = 0.0; [COLOR="Red"][B] // You are using "commission" without assigning a value to it first ![/B][/COLOR] if(commission <= 5000) commisionRate = 0.08; else if(commission <= 10000 && commission > 5000) commissionRate = 0.10; else commissionRate = 0.12; [COLOR="Red"][B] // LOL, firstname, lastname etc.. should not be in quotes, 'cuz they are vars. // And where is the ';' ?? [/B][/COLOR] cout << "firstname" << "lastname" << "commissionRate" << return 0; [COLOR="Red"][B]// You are pausing after returning from main() !![/B][/COLOR] system ("pause") [COLOR="Red"][B]// And where is ';' ??[/B][/COLOR] } The correct program can be like this : (Run it and tell me if it's useful) Code: #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.
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.