Computer Science, asked by abdiq2020, 11 months ago

Find the error(s), if any
1)
For ( x = 100, x >= 1, ++x )
cout << x << endl;
2)
The following code should print whether integer value is odd or even:
switch ( value % 2 )
{
case 0:
cout << "Even integer" << endl;
case 1:
cout << "Odd integer" << endl;
}

Answers

Answered by fablo34
0

Answer:

1)  in c++ , the for statement should have semicolons in between the expressions. Also, this has to be x-- otherwise it will become an infinite loop. So, the correct form will be for(x=100; x>=1; x--) cout<<x<<endl;

2) After specifying each of the cases in switch block you have to give a break keyword(excluding the last case as that is optional) . In switch case if the break statement is not given after a case then for a matching case it will execute that case statement as well as all the succeeding cases. So, it should be:

switch(value%2)

{

case 0: cout<<"Even Integer"<<endl;

            break;

case 1: cout<<"Odd integer"<<endl;

            break;

/*for this case 1 you may or may not provide the break keyword as it is the / last case and there are no default cases succeeding it.*/

}

Explanation:

Similar questions