|
-
July 4th, 2012, 09:37 PM
#1
PLEASE HELP A NOVICE WITH C++. How do i make this code output to a .txt file?
How do I make this code output/debug to a .txt file?
Here is the code:
#include <iostream>
using namespace std;
#define k 100 //force constant= 100 kcal/(mol*A^2)
#define m 16 //mass= 16 Daltons
float x;
float v;
float a; //acceleration
float t; //time
int z;
float dt;
int main ()
{
t=0;
int n;
cout << "Enter the Number of Iterations "<<"\n";
cin >> n;
z=1;
cout<< "Enter Initial Postion:"<<"\n";
cin >> x;
cout<< "Enter Initial Velocity:"<<"\n";
cin >> v;
cout<< "Enter Time Step: "<<"\n";
cin>>dt;
cout<<"t,x"<<"\n";
while (z<n)
{
a= -k*x/m;
x= x + v*dt + .5* a*dt*dt;
v=v+a*dt;
t=t+dt;
cout<<t;
cout<<" , ";
cout<<x<<"\n";
cout<<" ";
z=z+1;
}
system("pause");
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|