Like Tree1Likes
  • 1 Post By whiteflags

Input Validation

This is a discussion on Input Validation within the C++ Programming forums, part of the General Programming Boards category; Code: void BP::GetPressure() { cout << "Please enter your Diastolic Pressure readings: "; cin >> firstDiastolic >> secondDiastolic >> thirdDiastolic; ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    5

    Input Validation

    Code:
    void BP::GetPressure()
    {        
        cout << "Please enter your Diastolic Pressure readings: ";
        cin >> firstDiastolic >> secondDiastolic >> thirdDiastolic;
        cout << "Please enter your Systolic Pressure readings: ";
        cin >> firstSystolic >> secondSystolic >> thirdSystolic;
        
    }
    Any input on how I can get firstDiastolic, secondDiastolic, thirdDiastolic, firstSystolic, secondSystolic, thirdSystolic to accept only positive integers? I am trying to use a while loop but am having trouble with implementing this with conditions on six variables.

  2. #2
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Any input on how I can get firstDiastolic, secondDiastolic, thirdDiastolic, firstSystolic, secondSystolic, thirdSystolic to accept only positive integers?
    If this program isn't for a *very* serious purpose, just take the absolute value of whatever the user enters.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,556
    Let's see... what is the condition for when the input is valid?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,673
    Quote Originally Posted by Elysia View Post
    Let's see... what is the condition for when the input is valid?
    Blood pressure, how does it work?
    rags_to_riches likes this.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,556
    That was aimed at the OP, but just for the sake of it, I don't know the slightest of how it works.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Input/Validation
    By nokia123456 in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 11:26 AM
  2. input validation, kinda
    By dynamethod in forum C++ Programming
    Replies: 1
    Last Post: 09-15-2008, 12:52 AM
  3. c++ strings. input validation
    By Crashgr in forum C++ Programming
    Replies: 2
    Last Post: 08-24-2004, 06:54 PM
  4. Input Validation!
    By noaksey in forum C Programming
    Replies: 2
    Last Post: 05-02-2004, 05:19 AM
  5. Input validation
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-02-2001, 10:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21