any other comments?
🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
simple if question
@fleabay , it would be better if you don't post in Phil's threads.
@pbivens67 , please don't tell people to go to hell.
You both should know better.
Thread locked.
What are the symptoms of the problem? The original post seems like it should be doing what you want; you grab the point of a parabola, check if it's ≥ to the magic number, and then set it to the magic number if it is.
I do notice however that you're printing the value of y (with cout) before applying this clamping. Could that be causing you to think that your code doesn't work? What happens if you move the cout to after the if block?
I also notice that you generate the points in the parabola differently than you iterate through them; could you be mis-counting the number of points you're expecting to have (hence the subscript out of range) errors?
I took out the magic numbers. Here is my updated code.
#include <iostream>
#include <vector>
using namespace std;
vector <float> parabola;
float i = 0.0f, y = 0.0f, tier_one = 49.975f;
int state = 0;
void count()
{
for (float x = 22.5f; x >= -22.5f; x--)
{
y = (-0.1f * (x * x)) + 50;
parabola.push_back(y);
}
}
int main()
{
for (int j = 0; j < 46; j++)
{
count();
if (state == 0)
{
y = parabola[i];
i++;
}
if (y >= tier_one)
{
state = 1;
}
if (state == 1)
{
y = tier_one;
}
cout << y << endl;
}
return 0;
}
pbivens67 said:
I took out the magic numbers. Here is my updated code.
Why did you post this, Phil? Does it work now, or do you still have a problem? I wish you would tell us what your question is, when you have a question. If this code doesn't work, have you tried anything to figure out why it doesn't work? If so, what did you try? And then did you try something else? (etc.)