Check Price number in C++

Codeblocks Visual Studio Code

If you want to check if a given number is within a certain price range (for example, checking if it's within a range of valid prices), you can use a simple comparison in C++. Here's an example:

#include <iostream>
using namespace std;

int main() {
    double price;

    // Get the price from the user
    cout << "Enter a price: ";
    cin >> price;

    // Check if the price is within a valid range (for example, between 0 and 100)
    if (price >= 0 && price <= 100) {
        cout << "The price is within a valid range." << endl;
    } else {
        cout << "Invalid price. Please enter a price between 0 and 100." << endl;
    }

    return 0;
}

In this example, the program prompts the user to enter a price. It then checks if the entered price is within the range of 0 to 100. If it is, it prints a message indicating that the price is within a valid range. Otherwise, it prints a message asking the user to enter a valid price.

You can adjust the range (0 to 100 in this case) to fit your specific needs. If "Price number" means something different, please provide more context and I'll be happy to help further.

Comments
Loading...
Sorry! No comment found:(

There is no comment to show for this.

Leave your comment
Tested Versions
  • GCC 6.3.0