In my code:

#include <iostream> using namespace std; int main() { int T; cout <<"enter T:"<< endl; cin >>T; int a, b for (int i=0; i<T; i=i+1) { cout <<"enter a and b:"<< endl; cin >>a >>b; cout <<"a+b=" <<(a+b)<< endl; } return 0; } 

gives an error message:

 Compilation error main.cpp: In function 'int main()': main.cpp:10:9: error: expected initializer before 'for' for (int i=0; i<T; i=i+1) ^ main.cpp:10:23: error: 'i' was not declared in this scope for (int i=0; i<T; i=i+1) ^ 

I understand he does not like that i not used anywhere. What to do?

Closed due to the fact that off-topic by user194374, pavel , cheops , Mr. Black , Kromster Aug 2 '16 at 5:23 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - community spirit, pavel, cheops, mr. Black, Kromster
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • four
    You need to read the errors from top to bottom, that is, first solve the problem in the line: 10: 9 :, and then look further and not vice versa. And remember that the compiler often swears at the line that comes after the line with an error, that is, as a rule, the error is above the line: 10: 9: specified in this case - Dmitry Nail

1 answer 1

Lost semicolon.

 int a, b; //Здесь