What is wrong with my code1?

Dear Friends,
Would you please tell me why in the output of my code instead of t=0, it starts with t=69.09? I want to get the acc function values between t=0 and t=1 with constant time step 0.01

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  #include <iostream>

using namespace std;

double acc(double a) {

return (-10*a);
}

int main(){

	double t;
	const double dt=0.01;
    for (t=0; t*dt<=1; t+=dt)
	{
    	cout<<"t="<<t<<"\t"<<"t+dt="<<t+dt<<"\t"<<cout<<"acc="<< acc(t+dt)<<"\n";
	}
	return 0;
}
Last edited on
It should work fine as you posted (and it does on all online compilers)

However you have several flaws in logic:
for (t=0; t*dt<=1; t+=dt) Now it calculates values up to t = 100. I think you mean t < 1 
cout<<"t="<<t<<"\t"<<"t+dt="<<t+dt<<"\t"<<cout<<"acc="<< acc(t+dt)<<"\n";
Last edited on
Thanks a lot dear friend.
Topic archived. No new replies allowed.