Answer to Question #204205 in C++ for nazl

Question #204205

Identify and correct the errors in each of the following statements.

1) firstnumber =+ total

2) answer = X *(5Y)2;

3) if (x = 1);

cout << "Equal to 1"

else

cout <<"Not Equal to 1;

4)int n=1;

while (n>10);

cout << "HELLO \n"

n++;


1
Expert's answer
2021-06-08T02:13:30-0400

In c++, variables must be declared first before use.

So, it is a mistake to use firstnumber and total before declaring as variables.

Also, the first statement first assign (=) before adding (+)

Missing semicolon.

answer = X * (5 Y)2;

X and Y are not declared

No operators between 5 and Y and ) and 2

 if (x = 1); Missing opening curly bracket and presence of opening bracket

cout << "Equal to 1" - Missing terminating symbol (;)

-Closing curly bracket missing

else -Missing opening curly bracket

cout <<"Not Equal to 1; - Missing terminating quotation mark (")

int n=1;

while (n>10); - Presence of a semicolon after while statement and opening curly bracket is also missing

cout << "HELLO \n" missing semicolon.

n++; - Missing closing curly bracket

Correct codes are written below

1)
double total;
int firstnumber =+ total;
2) 
double answer;
int X, Y;
answer = X *(5* Y)*2;
3)
int x;
if (x = 1){
cout << "Equal to 1"<<endl;
}

else{
cout <<"Not Equal to 1"<<endl;
}
4) 
int n=1;

while (n>10){
cout << "HELLO \n";
n++;
}




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