Modify the following code to produce the output shown. Use proper indentation techniques. You must not make any changes other than inserting braces. The compiler ignores indentation in a C++ program. We eliminated the indentation from the following code to make the problem more challenging. [Note: It’s possible that no modification is necessary.]
if ( y == 8 )
if ( x == 5 )
cout << "@@@@@" << endl;
else
cout << "#####" << endl;
cout << "$$$$$" << endl;
cout << "&&&&&" << endl;
a) Assuming x = 5 and y = 8, the following output is produced.
@@@@@
$$$$$
&&&&&
b) Assuming x = 5 and y = 8, the following output is produced.
@@@@@
c) Assuming x = 5 and y = 8, the following output is produced.
@@@@@
&&&&&
d) Assuming x = 5 and y = 7, the following output is produced. [Note: The last three output statements after the else are all part of a block.]
#####
$$$$$
&&&&&
// Dangling-else problem.
#include
using namespace std;
int main()
{
int x = 5; // initialize x to 5
int y = 8; // initialize y to 8
// part a
if ( y == 8 )
{
if ( x == 5 )
cout << "@@@@@" << endl;
else
cout << "#####" << endl;
} // end if
cout << "$$$$$" << endl;
cout << "&&&&&" << endl << endl;
// part b
if ( y == 8 )
{
if ( x == 5 )
cout << "@@@@@" << endl;
else
{
cout << "#####" << endl;
cout << "$$$$$" << endl;
cout << "&&&&&" << endl;
} // end inner else
} // end outer if
cout << endl;
// part c
if ( y == 8 )
{
if ( x == 5 )
cout << "@@@@@" << endl;
else
{
cout << "#####" << endl;
cout << "$$$$$" << endl;
} // end inner else
} // end outer if
cout << "&&&&&" << endl << endl;
// part d
y = 7;
if ( y == 8 )
{
if ( x == 5 )
cout << "@@@@@" << endl;
} // end if
else
{
cout << "#####" << endl;
cout << "$$$$$" << endl;
cout << "&&&&&" << endl;
} // end else
} // end main
Computer Science & Information Technology
You might also like to view...
You have uploaded a file to S3. What HTTP code would indicate that the upload was successful?
A. HTTP 404 B. HTTP 501 C. HTTP 200 D. HTTP 307
Computer Science & Information Technology
If you have a long text entry, such as a paragraph, you can instruct Excel to ____________________ text in the cell.
Fill in the blank(s) with the appropriate word(s).
Computer Science & Information Technology