#include <iostream>
usingnamespace std;
int main()
{
int test[5];
int i,total;
for(i=0;i<5;i++)
{
cin >> test[i];
total=total+test[i];
}
cout<<endl<<endl;
for(i=0;i<5;i++)
cout<<test[i] <<endl;
cout<<total;
return 0;
}
When i run this code in DevC++ , and I input 10 ... 5 times, the total should be 50 but somehow in DEVC++ it will add extra 1 to the output so cout<<total is 51 instead. And if i copy this exact code to another IDE Embarcadero C++, with same input 10 ... 5 times, the output is 66
1) This issue is fixed when i initialize total=0 but I am curious why it worked in my lecturer's computer ( its recorded lecture and she did not initialize total=0 and she got the correct output which is 50.
2) Why is it different output in different IDEs?