Advertisement

simple if question

Started by June 26, 2023 11:19 PM
32 comments, last by pbivens67 1 year, 4 months ago

any other comments?

pbivens67 said:
any other comments?

My spoon is too big.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

Advertisement

go to hell fleabay try to be more positive

pbivens67 said:
try to be more positive

Sorry…

My spoon is just the right size.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

@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.

-- Tom Sloper -- sloperama.com

Thread unlocked at Phil's request.

-- Tom Sloper -- sloperama.com

Advertisement

thanks tom

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.)

-- Tom Sloper -- sloperama.com

This topic is closed to new replies.

Advertisement