Revanza Raytama
Revanza Raytama

Reputation: 13

Validation for multiplying value at C++?

I have to make a test where a number has to be the multiple of 500,

      do{
            cout << "Input Price[price>0|price multiple of 500]: ";
            cin >> price;
            cin.sync(); cin.clear();
        } while (price<1 || price>5000);

The code is still incomplete, I just have to add the following validation left. What do I do?

and also what is the right term for that kind of validation? I had a hard time determining the title.

Upvotes: 1

Views: 111

Answers (1)

quantdev
quantdev

Reputation: 23813

Add the following to your test :

price % 500 == 0

This is commonly called a modulo (finds the remainder of the division between two numbers) : if your price is a multiple of 500, then the remainder of the division between price and 500 is 0.

Upvotes: 7

Related Questions