In: Computer Science
Write C++ statements that will align the following three lines as printed in two 20 character columns.
Item Price
Banana Split 8.90
Ice Cream Cake 12.99
Item Price
Banana Split 8.90
Ice Cream Cake 12.99
C++ statements that will align the above three lines as printed in two 20 character columns:
#include <iostream>
using namespace std;
int main()
{
//character array initialization with the given values
char lines[3][2][20] = {{"Item", "Price"},
{"Banana Split", "8.90"},
{"Ice Cream Cake", "12.99"}};
//printing the lines in the required fashion
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 2; ++j) {
for(int k = 0;k < 20;k++)
{
//storing value of the character to the input value,if the value is null then storing space
char p = lines[i][j][k] == '\0' ? ' ' : lines[i][j][k];
cout << p;
}
}
cout << endl;
}
return 0;
}
CODE SCREENSHOT:
OUTPUT SCREENSHOT: