Instead of this:
Code:
for (int i=0; i<arraysize; i++)
d[i]=.5*9.8*t*+i;
cout<<" Time"<<setw(13)<< " Distance Traveled"<<endl;
for (int j=0;j<=t;j++)
{
tot =d[j];
cout<<setw(9)<<j<<setw(13)<<tot<<endl;
}
for (int s=j;s<=arraysize;s++)
{
cout<<setw(9)<<s<<setw(13)<<tot<<endl;
}
Try this:
Code:
for (int i = 1; i < arraysize + 1; i++)
d[i] = .5 * 9.8 * i * i;
cout << " Time" << setw(13) << " Distance Traveled"<< endl;
for (int j = 1; j <= t; j++)
cout << setw(9) << j << setw(13) << d[j] << endl;
for (int s = j + 1; s < arraysize + 1; s++)
cout << setw(9) << s << setw(13) << d[j] << endl;
However, I think this would be the simplest way to do it:
Code:
cout << setw(9) << t << setw(13) << (.5 * 9.8 * t * t) << "\n\n";
cout << " Time" << setw(13) << " Distance Traveled"<< "\n\n";
for(int i = 1; i < arraysize + 1; i++)
cout << setw(9) << i << setw(13) << (.5 * 9.8 * i * i) << endl;
This code will print out:
"
....<t>......<.5 * 9.8 * t * t>
...Time......Distance Traveled
......1........4.9
......2........19.6
......3........44.1
......4........78.4
......5........122.5
......6........176.4
......7........240.1
......8........313.6
......9........396.9
......10......490
" {substitute spaces for the periods}
everytime.