int main()
{
calc();
} // your main function ends here, was this intended?
{
// all code below here is both outside of main and not in a function so will not compile
double DFx,Dfy,Vx,Vy,Ax,Ay,T;
cout <<"What is your starting x position? ";
cin >> Ax;
cout <<"What is your starting y position? ";
cin >> Ay;
cout <<"What is your X velocity? ;" <<;
cin >> Vx;
cout <<"What is your Y velocity? "; <<;
cin >> Vy;
cout <<"What is X's acceleration? "; <<;
cin >> Ax;
cout <<"What is Y's acceleration? "; <<;
cin >> Ay;
cout <<"What is the time? ";
cin >> T;
DFx = Vx + (Ax * (T * T));
DFy = Vy + (Ay * (T * T));
system("pause");
return 0;
}
if the code below main is in fact what you wanted calc to do, you must put it into a function like this so that you can call it from main
1 2 3 4
void calc()
{
// your code here
}
also, system("PAUSE") and return 0 should be in main not inside of your function, many people will also shout at you for using system("PAUSE") at all, but that is a separate issue.
This advice is assuming that you wanted to run that code by calling calc() but it's hard to tell as the code as it stands makes no real sense.
Also, you will need to make sure main can access the function calc() by writing its body above the main function, or by writing it below main and forward delcaring it by putting
I never noticed that but you will need separate variables for x and y's starting position and acceleration, otherwise when the user inputs the acceleration it destroys the values for the starting positions
#include <iostream>
#include <cmath>
usingnamespace std;
void calc();
int main()
{
double DFx,DFy,Vx,Vy,Ax,Ay,T,x,y;
cout <<"What is your starting x position? ";
cin >> x;
cout <<"What is your starting y position? ";
cin >> y;
cout <<"What is your X velocity? ";
cin >> Vx;
cout <<"What is your Y velocity? ";
cin >> Vy;
cout <<"What is X's acceleration? ";
cin >> Ax;
cout <<"What is Y's acceleration? ";
cin >> Ay;
cout <<"What is the time? ";
cin >> T;
DFx = x + (Vx + (Ax * (T * T)));
DFy = y + (Vy + (Ay * (T * T)));
cout <<" "<<DFx<< ", "<<DFy<<
system("pause");
return 0;
}
the only problem: when i open it, it goes though then the answers then immediately gone.
do i put the system pause somewhere
F.Y.I i have visual c++ 2010
Look like line 25 isn't properly formed. Try this: cout <<" "<<DFx<< ", "<<DFy<<endl;
Also, make sure you have #include <cstdlib> if you are using system("pause")
Also I see that you have included cmath. That will allow you to replace (T*T) in your calculation with pow(T, 2). This is really convenient if you ever need larger exponents. More about it here: http://www.cplusplus.com/reference/clibrary/cmath/pow/
omg it works just fine
1 more question
if u wanna make it show different options for example
my answer came out as 1,1
i wanna make it so the code will show 5 different answers instead of 1
#include<iostream>
usingnamespace std;
int main()
{
char repeat = 'n';// user queried to repeat for another case
do// allows repeat runs and keeps window open so results can be seen
{
// code to repeat
cout << endl << "repeat (y/n)? " << flush;
cin >> repeat;
}while( repeat=='y');
return 0;
}
Also, I wanted to point out that your equations of motion are incorrect. If you are treating the case of constant acceleration then they should be:
1 2
DFx = x + Vx*T + 0.5*Ax*T*T;
DFy = y + Vy*T + 0.5*Ay*T*T;
not repeat a run of a code
list more than one answer
like 5 possible answers for the equation
lets say the equation was y=3x+3
it will display all of the possible answers on y=3x+3
u know wat i mean
No I don't know "wat" you mean. There are an infinite # of points on a line. You choose the starting value and the intervals. I don't think you know what you mean either.