i want to give user a double value.
if user give other than double value like string/alphanumeric/alphabets/some illegal values (ex:1;2), it should not accept as double and give an error message.
how to write it in c++.
i done this,but still it accepting "some integer followed by alphabets" ex:2ab,3sdf..... i want to accept only double values,it doesn't accept any values like: 5abc/0asd/asd/are any garbage values or illegal vales(1;2).
this is i tried:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main()
{
double val;
while(1)
{
cout<<"enter a double value :";
cin>>val;
if (cin.fail()== true)
{
// not a valid number
cout << "Invalid Input! Please input a numerical value." << endl;
cin.clear();
cin.ignore(100000, '\n');
}
else
{
// valid number
cout<<"valid.....";
break;
}
}
}