question

+1 Matt Belle · January 30, 2015
what if I wanted the user to enter his birth month and I don't know whether the user's input is integer or string 
for example july or 7 
what should I do ???

Post a Reply

Replies

Oldest  Newest  Rating
+1 Jay Deshaun · January 30, 2015
Get the type of the input.

https://www.google.ca/webhp?sourceid=chrome-instant&rlz=1C1KMZB_enCA577CA577&ion=1&espv=2&es_th=1&ie=UTF-8#q=get%20the%20type%20of%20input%20cin%20c%2B%2B - Google Search
http://www.cplusplus.com/forum/articles/6046/
+1 Anmol Wassan · January 30, 2015
You can use switch statement for this. User can type as per his wish.
for eg,
int n;
char str[10];
int i;
cout << "Enter 1 for number and 2 for words.
cin >> n;
switch(n){
case 1:
cin >> i; // which will initialize the month in number
break;
case 2:
cin >> str; // which will initialize the month in words
break;
default:
cout << "Invalid\n";
}
0 Matt Belle · January 30, 2015
thank you all guys ????
  • 1

C++

106,931 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator