Calculating a New position using velocity, and an old position

I have been working on this all week and still can't figure out how to calculate the new pixel position when i enter the starting pixel position and a velocity for the moving pixel. i know its something small that i'm missing, i just can't figure it out. The loop runs fine, its the calculating code thats giving me issues.

here is my code so far...

// Write a C++ program where you will input from the screen the starting point (pixel) and the velocity in pixels/sec.
// The program will then calculate where it will be on the screen for the next 45 frames (1 1/2 sec).
// So the output will consist of 45 numbers. Assume that 1 frame is 1/30th of a second.

#include "stdafx.h"
#include "iostream"

using namespace std;
using namespace System;

// This function calculates the new position of an object.
// The old position, velocity, and time are passed to it.

float New_Position (float Old_Position, float v, float t)
{
return Old_Position + v*t ;

Old_Position = New_Position;
}



int main(array<System::String ^> ^args)
{
float Old_Position;
float v;
int frame = 0;
float t;

// welcoming comments

cout << "welcome to pixel position locator" << endl;
cout << "this program calculates the new pixel position based on" << endl;
cout << "a user's input original position and velocity." << endl;
cout << "Please follow the prompts carefully" << endl;
cout << endl;

// in this section the user inputs the starting position

cout << "please enter a value for original pixel position (starting point)" << endl;
cin >> Old_Position;
cout << "thank you" << endl;
cout << endl;

// int the section the user inputs the velocity

cout << "please enter a value for the velocity (px/s)" << endl;
cin >> v;
cout << "thank you" << endl;
cout << endl;

while ( frame < 45 )
{
t = 1/30;
Old_Position = New_Position;


//increments frame by 1 everytime the loop goes through

frame ++;


//This function calculates the new position of an object. The old
//position, velocity, and time are passed to it.

New_Position (Old_Position, v, t);
{
Old_Position + (v * t) ;
};

cout << " your new position at frame # " << frame << " is pixel x= " << New_Position << endl;



};

system("pause");
return 0;
}


any help would be greatly appreciated. thanks.
Old_Position = New_Position;

where is the New_Position variable? =P
Also, you tried to write a New_Position function inside of main?

You do alot of weird stuff in your code, you should comment each line on what you think youre doing (in the while loop, everything before the while loop is perfectly fine) because there are tons of strange mistakes you make, i think if you look at the code line by line, you might even figure it out.
Last edited on
@ Skillless

thanks for your reply. i found the simple mistakes i made and got the code to run properly. the code i originally posted was after i had been messing around with it, but i forgot to remove the experimental code.
Topic archived. No new replies allowed.