Why does this malfunction when you enter letters?

#include <iostream>
using namespace std;


int main()

{


double a;
double b;

cout<< "Enter your number" << endl << "HERE:";
cin>>a;
cout<< "Your number is:" << a;
cin>> b;

cin.get();

return 0;
}


Just curious.
Last edited on
This isn't malfunctioning, this is behaving exactly as programmed: the operation "cin>>a" fails because "letters" are not a value of type double, and the operation "cin>>b" also fails because you haven't corrected the first error.
"cin>>a" fails because "letters" are not a value of type double

What could I put that supports letters?
Strings accept all letters. If you replace double a; with string a;, it will not fail.
Thank you.
If you are using one letter you should just use a char type:
char a;
This holds one character of either a letter or number.
it will save memory and if you want a short string use an array of characters.
char a [10]; // this holds up to ten characters.
Remember this: A numeric value, such as an integer, is stored as a binary code in the computer and for this to but printed out on the screen, cout (which is a smart object) must convert the number into a stream of single characters.
Topic archived. No new replies allowed.