Write a statement that reads 5 successive integers into these variables that have already been declared: x1 x2 x3 x4 x5. Then write a statement that prints each out on its own line so that they form a right-justified column with a 5-digit width. If any of the integers are 5-digits in size, then they will start at the very beginning of their lines. For example: |54213 | 8713 | 23 | 147 | 15 NOTE: The vertical bar,|, on the left above represents the left edge of the print area; it is not to be printed out. Also, we show x in the output above to represent spaces–your output should not actually have x’s!
LANGUAGE: C++
CHALLENGE:
Write a statement that reads 5 successive integers into these variables that have already been declared: x1 x2 x3 x4 x5. Then write a statement that prints each out on its own line so that they form a right-justified column with a 5-digit width. If any of the integers are 5-digits in size, then they will start at the very beginning of their lines. For example: |54213 | 8713 | 23 | 147 | 15 NOTE: The vertical bar,|, on the left above represents the left edge of the print area; it is not to be printed out. Also, we show x in the output above to represent spaces–your output should not actually have x’s!
SOLUTION:
cin >> x1 >> x2 >> x3 >> x4 >> x5; cout.setf (ios::right, ios::adjustfield); cout << setw(5) << x1 << "\n" << setw(5) << x2 << "\n" << setw(5) << x3 << "\n" << setw(5) << x4 << "\n" << setw(5) << x5 << "\n";