Assume that scotus is a two-dimensional character array that stores the family n
ID: 3935621 • Letter: A
Question
Assume that scotus is a two-dimensional character array that stores the family names (last names ) of the nine justices on the Supreme Court of the United States. Assume no name is longer than twenty characters . Assume that scotus has been initialized in alphabetical order. Write some code that will print each to standard output , each on a separate line with no other characters .
MY CODE
for (int i = 0; i < 9; i++)
{
int j = 0;
while (j < 20)
{
cout << scotus[i][j];
j++;
if(scotus[i][j] == ' ')
{
cout << endl;
break;
}
}
cout << endl;
}
Expected Output:
Actual Output:
Result Feedback soutAlitoThe value of sout is incorrect.
ThomasThe value of sout is incorrect.
RobertsThe value of sout is incorrect.
Explanation / Answer
This condition in your code is wrong : if(scotus[i][j] == ' ')
Character arrays end with '' when string is complete, so change it to if(scotus[i][j] == '' )
Also you can directly write the code as:
for (int i = 0; i < 9; i++)
{
cout << scotus[i] << endl;
}
as cout, stops printing when '' is found