Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.6 kB
2
Indexable
Never
#include "input_prot.h"

#include <iostream>
#include <limits>

void validate_input_range(double & number, const std::string & booo)
// FOR SKIP/ABORT, USE A PROMPT
{
	using namespace std;
	
    cin >> number; 
	
	while (number < 0 || number > 100 || cin.fail())
	/* {
        cin.clear();
        cin.ignore();
        if (number < 0 || number > 100 || cin.peek() == '\n')
        {
            cout << booo;
        }
        cin >> number;
    } */
    {
        cin.clear();
        cin.ignore();
        if (number < 0 || number > 100 || cin.peek() == '\n')
        {
			/* char answer; */
            cout << booo << endl;
			/* cin >> answer; */
        
			/* if (answer == 'y' || answer == 'Y')
			{
				cout << "Please retry..." << '\n';
				cin >> number;
			}
			else if (answer == 'n' || answer == 'N')
			{
				cout << "Continuing..." << '\n';
				break;
			}
			else if (answer == 'a' || answer == 'A')
			{
				cout << "Aborting..." << '\n';
				abort();
			} */
		}
		cin >> number;
    }
	cout << "Valid input..." << endl;
    return;
}

void validate_input_limits(double & numbermax, const std::string & erron) 

{
	using namespace std;
	
    cin >> numbermax;
    while (numbermax > numeric_limits<double>::max() || cin.fail())
    {
        cin.clear();
        cin.ignore();
        if (numbermax > numeric_limits<double>::max() || cin.peek() == '\n')
        {
            cout << erron;
        }
        cin >> numbermax;
    }
    return;
}


void validate_input_positive(double & numberpositive, const std::string & errod)

{
	using namespace std;
	
    cin >> numberpositive;
    while (numberpositive < 0 || cin.fail())
    {
        cin.clear();
        cin.ignore();
        if (numberpositive < 0 || cin.peek() == '\n')
        {
            cout << errod;
        }
        cin >> numberpositive;
    }
    return;
}

void validate_input_positive(long & longnum, const std::string & errorm)

{
	using namespace std;
	
    cin >> longnum;
    while (longnum < 0 || cin.fail())
    {
        cin.clear();
        cin.ignore();
        if (longnum < 0 || cin.peek() == '\n')
        {
            cout << errorm;
        }
        cin >> longnum;
    }
    return;
}

void validate_input_range(long & longrng, const std::string & errom)

{
	using namespace std;
	
    cin >> longrng;
    while (longrng < 0 || longrng > 100 || cin.fail())
    {
        cin.clear();
        cin.ignore();
        if (longrng < 0 || longrng > 100 || cin.peek() == '\n')
        {
            cout << errom << endl;
        }
        cin >> longrng;
    }
    return;
}

void validate_input_limits(long & longmax, const std::string & error)

{
	using namespace std;
	
    cin >> longmax;
    while (longmax > numeric_limits<long>::max() || cin.fail())
    {
        cin.clear();
        cin.ignore();
        if (longmax > numeric_limits<long>::max() || cin.peek() == '\n')
        {
            cout << error;
        }
        cin >> longmax;
    }
    return;
}

void validate_input_limits(char & charthing, const std::string & errorm)

{
	using namespace std;
	
    cin >> charthing;
    while (charthing > numeric_limits<char>::max() || cin.fail())
    {
        cin.clear();
        cin.ignore();
        if (charthing > numeric_limits<char>::max() || cin.peek() == '\n')
        {
            cout << errorm;
        }
        cin >> charthing;
    }
    return;
}