When a ball is thrown upward at an angle of x degrees and with initial velocity V0 the height of the ball after t seconds is
h(t) = V0t sin( x) - 16 t2

Using an initial velocity of 144 feet per second and x = 60 degrees, write a program to output a table giving the height of the ball for each value of t from 0.5 to 8.0 in increments of 0.5 seconds.

This is what I had so far.

 12345678910111213141516 #include using namespace std; #include int main() { int x=60; //x is the measure of angle in degrees. int V= 144; //Initial velocity int t; //Seconds int h; // height h = V*t*sin(x)- 16t^2; cout << setw(3) << "Time" << setw(3) << "Height" << endl; cout <

closed account (3qX21hU5)
Ok so what are you having trouble with?

I see some things wrong with it already but they might be just because the program is not complete but I'll list them anyways

1) in h = V*t*sin(x)- 16t^2; you are using t even though it has not yet been defined so you will get undefined behavior since you have no clue what number will be in int t. Never use a variable unless you are assigning to it without first defining it.

2) Probably nothing but on line 16 you are missing a semicolon.

But again we cant help you at all unless you ask a question. Just stating your assignment and what you have doesn't let us know what you are stuck on.
How to calculate and output each value of h for every value of t in seconds starting from 0.5 to 8 by .5s
Last edited on
closed account (3qX21hU5)
You would do it in a loop that starts at .5 and keeps looping until it hits 8. Here is some framework for your problem.

 12345678910 double t = 0.5; // Remember to use double or float when working with decimals // Once t is equal to 8 the loop will stop. while (t != 8) { // This is where you will put the math to calculate h for every .5 seconds // You will also put the output here. //This increases t by .5 every time it goes through the loop. t += 0.5; }

Hope this helps.
Last edited on
The way you have the equation written is incorrect in c++. Sin takes radians not degrees and t^2 isn't t squared. Try this instead h = V*t*sin(x*M_PI/180) - 16*t*t;

Is this right?

 12345678910111213141516 int x=60; //x is the measure of angle in degrees. int V= 144; //Initial velocity double t= 0.5; //Seconds int h; // height cout << setw(3) << "Time" << setw(3) << "Height" << endl; while(t!=8) { h = V*t*sin(x*M_PI/180)- 16t^2; t += 0.5; cout << set(3) << t << set(3) << h << end;l } return 0;
Last edited on
No, 16t^2 isn't doing what you think it is, it is not 16t squared. You need to change it to 16*t*t. See this working code http://ideone.com/LLVyIl
closed account (3qX21hU5)
Also your increasing t before you output, make sure you output the result first then increase t.
naraku,PEMDAS. Exponents come before multiplication. So it is 16* (t^2).
Parentheses around the t^2 here to emphasize the order of op. But thanks for trying to help anyway.
^ doesn't have anything to do with exponents in C++.
t to the 2nd power.
closed account (3qX21hU5)
I don't think you understand
 ^ doesn't have anything to do with exponents in C++.

^ is the XOR (Exclusive Or) operator. This operation is performed between two bits (a and b). The result is 1 if either one of the two bits is 1, but not in the case that both are. There for, if neither or both of them are equal to 1 the result is 0.

They are giving you the right answer but you are unwilling to take it.

I just wasn't sure if they were correct. I am still learning and I think I am allowed to doubt.
 I am still learning and I think I am allowed to doubt.

Because you're still learning, you should question yourself. Not the myriad people who say you're wrong.

At any rate, if you have an assumption and you believe it to be correct despite someone saying it's not... test it instead of being ignorant and asserting you are correct.
closed account (3qX21hU5)
Your right you can doubt it if you want, but generally when you are still just learning and 2 experienced C++ programmer try and give you advice it is usually a good idea to listen to it instead of doubt it. Some mathematical operators are the same in C++ but a lot of them are different and it can get confusing sometimes.
I have a quadratic formula program:

Sorry, haven't modified it yet to do i.