0
Why do i get a time out error in my while loop code in c++
Time out error https://code.sololearn.com/cMocAfK0H1eq/?ref=app https://code.sololearn.com/cMocAfK0H1eq/?ref=app
3 Answers
+ 1
You declared int a twice.
Remove int a = a+1;
Replace with a = a+1;
(or even better, a+=1;)
Global variable a never hits 10, while loop then runs infinite times.
Turn the local a to global a (by removing int) and it works! :)
int main()
{
int a=0;
int b=10;
int sum;
while (a<10) {
sum=a+b;
cout<<sum;
a= a+ 1; // declared twice
}
return 0;
}
0
Help me out with this..
0
I see thank you



