2
#include<iostream>
using namespace std;
int main()
{
    double money;
    cout << "Input the sum of money: ";
    cin >> money;
....

I have been trying to check if the value entered is a numeric value so that i can display an error message if another value (alphabetic letter) is entered and the code will loop back to ask for the input again (the money)

user2864740
  • 60,010
  • 15
  • 145
  • 220

2 Answers2

2
while ( ( cin >> money ) == false )
{
...
}
kuhar
  • 338
  • 1
  • 2
  • 10
2

You can check the state of the stream after the input. For example

if ( !( std::cin >> money ) ) std::cout << "Oh, I made a mistake!\n";

And if you want to repeat the input you should call

std::cin.clear();
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );

Do not forget to include header <limits>

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335