Answer to Question #185318 in C++ for samadi de silva

Question #185318

Question 01

Write only nested if statements to print the message based on the flag user has entered. The scheme is as follows,

Flag Message

1 or 2 Left

3 to 5 Forward

6 Backward

7 Right


Question 02

Identify the errors in each of following statement

1)answer = 2Y+ X5 + 3Z

2)if(x=>1);

cout <<"Equal to 1" <<endl;

cout<<"Greater than 1 "<<endl;

else

cout<<"Not equal to 1"<<endl;

cout<<"End of else"<<endl;

1
Expert's answer
2021-04-28T20:16:29-0400

Question 1


#include <iostream>


using namespace std;




int main()


{


   int flag;


   cout<<"Enter a flag: ";


   cin>>flag;


   if (flag<=7)


   {


      if(flag==1 || flag==2){


          cout<<"1 or 2 Left"<<endl;


      } 


      if (flag>=3 && flag<=5){


          cout<<"3 to 5 forward"<<endl;


      }


      if (flag==6){


          cout<<"Backword"<<endl;


      }


      if (flag==7){


          cout<<"Right"<<endl;


      }


   }




   return 0;


}

 

Question 2

1.     Error: there is no operators between the variables and the numbers

2.     Errors:

·        The if statement is not enclosed with curly brackets.

·        The else statement is not enclosed with curly brackets.

·        The head of if statement has a semicolon.


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS