how do i store a result in a variable

calculate the value S according to the formula S = (1.0/2)*a*t^2 and store that result in the variable distance. I have everything else set up, this is the only thing im stuck on. the variable type of distance is double.
Understanding that topic is fairly fundamental. You'd probably benefit from going through the tutorial.
http://www.cplusplus.com/doc/tutorial/variables/
i read through it but im still having trouble with it
Ok, I (and others) am willing to help. However, it's not clear where you are stuck.
Maybe you could post the code you've written for this so far and we'll take it from there.
Also, did you look at the assignment operator here:
http://www.cplusplus.com/doc/tutorial/operators/
Last edited on
#include <iomanip>
#include <iostream>
using namespace std;

int main()
{
float acceleration = 24.0;
float time = 8.0;
double distance;
Here :D distance=/*that formula*/;
its giving me the error : expected an expression
What exactly is giving you an error?

double distance;
distance = /* (1.0/2) * acceleration * time ^ 2*/;

how can i fix this
/* */ are comment pairs... the compiler reads this as distance = ;
oh, i previously tried it without it like this distance = (1.0/2) * acceleration * time ^ 2;
and it gave me the error: expression must have integral or unscoped enum type
^ does not mean "to the power of" in C++, just do time * time.
Last edited on
wow i cant believe i forgot about that. thanks i finally finished it
Topic archived. No new replies allowed.