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++;
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
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++;
}
Comments
Leave a comment