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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
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 <<set(3) << "0.5" << h
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.
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.
1 2 3 4 5 6 7 8 9 10
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;
^ 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.
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.