Assume that scotus is a twodimensional character array that

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
sout
\"redX.png\"
  Alito  
The value of sout is incorrect.
\"redX.png\"
  Thomas  
The value of sout is incorrect.
\"redX.png\"
  Roberts  
The value of sout is incorrect.

Solution

This condition in your code is wrong :   if(scotus[i][j] == \' \')

Character arrays end with \'\\0\' when string is complete, so change it to if(scotus[i][j] == \'\\0\' )

Also you can directly write the code as:

for (int i = 0; i < 9; i++)
{
   cout << scotus[i] << endl;
}

as cout, stops printing when \'\\0\' is found

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 State

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site