error on a simple program

The problem is when i entered letters the program keep saying
"Invaild number entered--Try again: ""Enter a double number: "
it just wont let me cin the number[count];

const int SIZE =20;
double* number = new double[SIZE];
int count = 0;
do {
cout << "Enter a double number: ";
cin >> number[count];

while (!cin.good() && !cin.eof()) {
cout << "Invaild number entered--Try again: ";
cin >> number[count];
system("PAUSE");
}
}while(!cin.eof());

Thank You
Last edited on
Do you wanna only numbers in your program and ignore the letters? if yes, you can ignore strings data type in your program with the scanf() function. For example:

scanf("%[A-Z]s", str);

in this code, I ignore any char of A at Z.

----------------------
Sorry any english error, I from Brazil.
Can I ask why you're trying to enter letters in a double array?
Ty. andrezc i never used scanf before, but i tried those scanf in my program. so what if a user entered a string instead of letters.

for Packetpriate, in this program i need to test for invaild number. for instance, if user entered a letter or a string, i should let user enter the number again.

I just dont get it why it doesnt go to if statement of cin.

Thank You guys
Oh. Well if your trying to avoid a cin>> error when user enter non number chars you should be using this:
1
2
3
4
5
6
while ( !std::cin )
{
  std::cin.clear()
  std::cin.ignore( std::numeric_limits< std::streamsize >::max(), '\n');
  std::cout << "Invalid Number. Please Retry: "; std::cin >> number[count];
}


EDIT: You'll need to #include <limits> for this code.
Last edited on
Ty. andrezc i never used scanf before, but i tried those scanf in my program. so what if a user entered a string instead of letters.


Oh, sorry. You using C++... :D
Ty guys
Long time didn't touch to c++, always working on java and almost forgot how to write it ;p
Topic archived. No new replies allowed.