Foreach loop behaviour and manipulation

Binarydepth binarydepth at gmail.com
Thu Nov 28 15:50:12 PST 2013


I fixed a formatting problem on the code just now. And also a 
note is that the numbers are supposed to display a number 
depending on the initial value of the variable that the foreach 
loop is increasing and the users age.

So if you were born in 1977 you input your birth year to the 
program and you'll get :

136:136
236:236
336:336
436:436
536:536
...
1036:1036
1136:1136
1236:1236
...
2036:2036
2136:2136
....
5036:5036
end

------------------------------------------------------------------------
import std.stdio : write, readf;
void main()
{
int a, r, f, temp;
int[102] arr;
write("Digite su año de nacimiento : ");
readf(" %d", &a);
write("\n");
foreach(t; 1..51)
     {
	temp=t;
	t*=20;
	t+=402;
	t*=5;
	t+=3;
     arr[temp-1]=t-a;
	t=temp;
	t*=5;
	t+=50;
	t*=20;
	t+=1013;
     arr[temp]=t-a;
     t=temp;//Do I need this for the foreach loop to work as 
intended ?
	}
write("BD\tAnonimo\n");
foreach(count; 0..102)
     {
         write(arr[count]);
         if(count%2!=0 && count!=0)
         write("\n");
         else
         write(" : ");
     }
}
-------------------------------------------------------------------------------


More information about the Digitalmars-d-learn mailing list