First, a short grammar lesson. (Sorry.)
“inline” is not the same as “in-line”
Inline means something is not separated out from the surrounding context. For example, an
inline function is one where the compiler doesn’t actually create a function, but just puts the code that would have been in that function in the same place that function would have been called.
1 2 3 4 5 6 7 8 9 10
|
// What you write:
inline void hello() { std::cout << "Hello world!\n"; }
int main()
{
std::cout << "Welcome to the show!\n";
hello();
std::cout << "That’s all folks!\n";
}
|
// What the compiler pretends you wrote:
int main()
{
std::cout << "Welcome to the show!\n";
std::cout << "Hello world!\n";
std::cout << "That’s all folks!\n";
} |
In-line means that something is lined-up in a straight line. You posted no example of what line you meant, but I will assume you want output like this:
Employee: John Penny
Salary: 3461.54 (90000/yr)
Pay Periods: 26
Exemptions: 4
Insurance: 531.69 (13834/yr)
FICA: 214.62
Withholding: 398.08
Net Pay: 2317.15 |
You cannot align multiple outputs as a single field. You need to use a stringstream to create a
single output field, then align-print that.
1 2 3 4 5 6 7 8 9
|
cout << right << fixed;
cout << "Employee: " << setw(26) << employeeName << "\n";
cout << "Salary: " << setw(23) << (ostringstream{} << fixed << setprecision(2) << totalPayPeriod << " (" << yearlySalary << "/yr)").str() << "\n";
cout << "Pay Periods: " << setw(23) << payPeriod << "\n";
cout << "Exemptions: " << setw(23) << numExemptions << "\n";
cout << "Insurance: " << setw(23) << (ostringstream{} << fixed << setprecision(2) << totalHealth << " (" << setprecision(0) << healthInsurance << "/yr)").str() << "\n";
cout << "FICA: " << setw(23) << setprecision(2) << totalFICA << "\n";
cout << "Withholding: " << setw(23) << setprecision(2) << totalTaxWithExemptions << "\n";
cout << "Net Pay: " << setw(23) << setprecision(2) << netPay << "\n";
|
BTW, I presume this is a homework. If you are doing anything for
actual employee salaries you should absolutely not be using floating point. Use integers for that data and
only convert to float for printing output, as that will be exact:
1 2 3 4 5
|
unsigned long long insurance = 386000; // in pennies. Many places do it in hundredths of a penny
int payperiod = 4;
unsigned long long health = insurance / payperiod;
std::cout << "health = $" << (health / 100.0) << "\n";
|
Hope this helps.