1
這是我的代碼:格式化C++輸出兩列不同的理由
cout << fixed <<showpoint<<setprecision(2);
cout << setw(10) << left << "Employee:"<< right << setw(9) << name <<endl;
cout << setw(10) << left << "Hours Worked:"<< right << setw(9) << hrWork <<endl;
cout << setw(10) << left << "Hourly Rate:"<< right << setw(9) << hrRate <<endl;
cout << setw(10) << left << "Total Wages:"<< right << setw(9) << tWages <<endl << endl;
cout << left << setw(10) << "Federal Withholding:"<< right << setw(9) << fedW <<endl;
cout << left << setw(10) << "State Withholding:"<< right << setw(9) << staW <<endl;
cout << left << setw(10) << "Hospitalization:"<< right << setw(9) << hosp <<endl;
cout << left << setw(10) << "Union Dues:"<< right << setw(9) << uniDues <<endl;
cout << left << setw(10) << "Total Deductions:"<< right << setw(9) << tDeduc <<endl;
cout << left << setw(10) << "Net Pay:"<< right << setw(9) << netP <<endl;
這是我的電流輸出(我試過集(W)和理由的幾個方面,這是我能得到的最接近):
Employee: Anthony
Hours Worked: 20.00
Hourly Rate: 8.75
Total Wages: 175.00
Federal Withholding: 31.50
State Withholding: 7.88
Hospitalization: 25.65
Union Dues: 3.50
Total Deductions: 68.53
Net Pay: 106.47
這就是我的目標是在(兩列一個調整到左邊,另一個在右邊):
Employee: Anthony
Hours Worked: 20.00
Hourly Rate: 8.75
Total Wages: 175.00
Federal Withholding: 31.50
State Withholding: 7.88
Hospitalization: 25.65
Union Dues: 3.50
Total Deductions: 68.53
Net Pay: 106.47
我該怎麼做?謝謝
您能否將您的預期輸出格式化爲列,以便我們知道您的期望?你的問題說兩列,但看起來你有兩列以上的數據。 – Jay
也許我不應該說專欄。代碼的第三部分包含我期待的內容。 –