Main.cc: In function ‘int main()’: Main.cc:23:22: error: ‘flag’ was not declared in this scope else if(a[i]=='r'&&flag) sum+=c; ^~~~ Main.cc:23:22: note: suggested alternative: ‘log’ else if(a[i]=='r'&&flag) sum+=c; ^~~~ log