hi i started learnin c++ and i just cant understand this code:
// arrays example
#include <iostream.h>
int billy [] = {1, 2, 3, 4, 5};
int n, result=0;
int main ()
{
loop1: cout << "input a number smaller than 5 \n ";
cin >> n;
if (n>=5)
goto loop1;
for( n ; n<5 ; n++ )
{
result += billy[n];
}
cout << result;
return 0;
}
i even made the arrays very small to try to understand it but i just cant!! heres my understanding..
i input a n say like 2
then in the formula result += billy[n] means..? result += result + billy[3]??
this is weird the outcome are as follows when i enter the numbers
0=15
1=14
2=12
3=9
4=5
please shed some light for this newbie