-4

Program to find the first largest number from the entered 5 number. When program says user to enter the first number then Check whether the entered statement is string or not if it is a string then call a user defined function in that is named as error() if it is a integer then store it and ask the user to enter second number.

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154

1 Answers1

0

You can enter integers directly via cin in <iostream>:

int number;
std::cin >> number;

If the entered string is not a number, cin.fail() will be set:

if(std::cin.fail()) {
    // error handling...
}
npas
  • 163
  • 2
  • 7
  • 1
    Unfortunately, this does not work for cases like "5w" and "12.34". – Thomas Matthews Jul 23 '18 at 14:22
  • @ThomasMatthews I've written a [small test program](https://pastebin.com/pYcGadnU) and you seem to be right. However, in the very specific case of OP, it might just be enough. If you enter "344w" and `cin` parses `344`, it is good enough to work with for a largest-number program. Concerning your second example, since OP specified *integer*, I did not look for a floating-point solution. – npas Jul 23 '18 at 14:36