I am trying to take user input as floating point only. to expect such value
Enter a floating-point number: a Please enter floating-point only: 123.45 floating-point number: 123.45 You entered: 123.45
Here is what I have tried so far.
#include <iostream>
using namespace std;
double readDouble(string prompt){
prompt = cout << "Enter a floating point number: ";
if (cin.fail())
cout << "Numbers Only Please " << endl;
return 0;
}
int main() {
double value = readDouble("Enter a floating-point number: ");
cin >> value;
cout << "You entered: " << value << endl;
if (cin.fail())
cout << "Please Enter Numbers only Please " << endl;
}
while (true){
if (cin != value);
cout << "Number Only!!" << endl;
cin >> value << endl;
}