Answer to Question #185930 in C++ for samadi

Question #185930

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-28T04:24:52-0400

Question 1


#include <iostream>

 

using namespace std;

 

int main()

{

   int n;

   cout<<"Enter a flag: "

   cin>>n;

   if (n<=7)

   {

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

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

      } 

      if (n>=3 || n<=5){

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

      }

      if (n==6){

          cout<<"Backword"<<endl;

      }

      if (n==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