### Preventing letter/symbol input

Hi, basically trying to stop letters and symbols being entered into my main function. For the menu section I used a buffer yet I try this with my function and its not working. Any help would be great appreciated and it is for the code below.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081`` ``````#include #include #include #include using namespace std; struct Point3D { float x; float y; float z; } V1, V2; double CalculateDistance(Point3D * V1, Point3D * V2); double CalculateLenth(Point3D* * V1, Point3D* * V2); int main(void) { string buffer; char choice; // variables double distance; double length; do { do { system("CLS"); cout << "Welcome to the Distance Calulator for 3D points" << endl; //main menu cout << "1. Go" << endl; //commence distance calculating cout << "2. Quit" << endl; //quit the application cin >> buffer; } while(buffer.length() > 1); //limiting the user to enter 1 numerical character to being the application choice = buffer[0]; if (choice == '1') { cout << "Enter Vertex 1's X co-ordinate: "; cin >> V1.x; cout << "Enter Vertex 1's Y co-ordinate: "; // Vertex 1's co-ordinates cin >> V1.y; cout << "Enter Vertex 1's Z co-ordinate: "; cin >> V1.z; cout << "Enter Vertex 2's X co-ordinate: "; cin >> V2.x; cout << "Enter Vertex 2's Y co-ordinate: "; // Vertes 2's co-ordinates cin >> V2.y; cout << "Enter Vertex 2's Z co-ordinate: "; cin >> V2.z; distance = CalculateDistance(&V1, &V2); cout << "Distance between V1 and V2 = " << distance << endl; // outputting the total distance cout << " " << endl;; cout << "Do you want to calculate another distance ?" << endl; // option to carrying on the application cout << "Press '1' to go back to the main menu, or '2' to quit." << endl; cin >> choice; } } while(choice != '2'); //the start of the sequence if the user chooses to end the application cout << "Goodbye"; Sleep(500); // makes the computer 'wait' for 500 milli-seconds return 0; // end the application } double CalculateDistance(Point3D * V1, Point3D * V2) { double distance; distance = sqrt(pow(V1 -> x - V2 -> x, 2) + pow(V1 -> y - V2 -> y, 2) + // distance calculator for the first function pow(V1 -> z - V2 -> z, 2)); return distance; }``````
Topic archived. No new replies allowed.