Quote:
Originally Posted by Prof. Krauf
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.