### Restart Program Function?

Hi, I've created a simple "Distance Calculator" for a game that I play frequently that uses grid/graph points occasionally, basically you tell it two (x, y) coords and it runs the distance formula on them.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344`` ``````/* This program is a distance calulator for arma 2/DayZ */ #include "stdafx.h" #include #include using namespace std; int main(int argc, char *argv[]) { int x1, y1; int x2, y2; int x1k, y1k; int x2k, y2k; int km; int ad; cout << "Choose Unit of Measure 1=Km, 2=M ", cin >> km; if (km == 1) { cout << "You've Chosen Kilometers." << endl; cout << "Enter X1 = ", cin >> x1k; cout << "Enter Y1 = ", cin >> y1k; cout << "Enter X2 = ", cin >> x2k; cout << "Enter Y2 = ", cin >> y2k; cout << "Distance From (" << x1k << ", " << y1k << ") to (" << x2k << ", " << y2k << ") = " << (sqrt(pow(((x2k - x1k)/2.00), 2.00) + pow(((y2k - y1k)/2.00), 2)))/5.00 << "km" << endl; system ("PAUSE"); } else { cout << "You've Chosen Meters." << endl; cout << "Enter X1 = ", cin >> x1; cout << "Enter Y1 = ", cin >> y1; cout << "Enter X2 = ", cin >> x2; cout << "Enter Y2 = ", cin >> y2; cout << "Distance From (" << x1 << ", " << y1 << ") to (" << x2 << ", " << y2 << ") = " << ((sqrt(pow(((x2 - x1)/2.00), 2.00) + pow(((y2 - y1)/2.00), 2.00)))/5.00)*1000.00 << "m" <> ad; if (ad == 1) { } return 0; }``````

Anyway, as you may have noticed, at the end there, there is an empty space,

cout << "Would you like to find another distance? (1=Yes, 2=No) ", cin >> ad;

}

and as mentioned in the title of this thread, I am asking if there is a way that, if the user enters 1 to restart and find another distance it will start the program from the top of the script.
All help is appreciated, thanks in advance!
~Michael
What you are looking for would be a loop.

You can learn about them here: http://www.cplusplus.com/doc/tutorial/control/

Just put whatever code you need to repeat within a loop.
thanks that did the trick!
Topic archived. No new replies allowed.