1
 /*
 PROGRAM: Ch6_14.cpp
 Written by Corey Starbird
 This program calculates the balance
 owed to a hospital for a patient.
 Last modified: 10/28/13
 */

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;

// Prototypes for In-patient and Out-patient functions.
double stayTotal (int, double, double, double); // For In-patients
double stayTotal (double, double);              // For Out-patients

int main()
{

    char    patientType;        // In-patient (I or i) or Out-patient (O or o)
    double  rate,               // Daily rate for the In-patient stay
    servCharge,                 // Service charge for the stay
    medCharge,                  // Medication charge for the stay
    inTotal,                    // Total for the In-patient stay
    outTotal;                   // Total for the Out-patient stay
    int     days;               // Number of days for the In-patient stay

    // Find out if they were an In-patient or an Out-patient
    cout << "Welcome, please enter (I) for an In-patient or (O) for an Out-patient:" << endl;
    cin >> patientType;
    while (patientType != 'I' || 'i' || 'O' || 'o')
    {
        cout << "Invalid entry. Please enter either (I) for an In-patient or (O) for an Out-patient:" << endl;
        cin >> patientType;
    }



    cout << "FIN";

    return 0;
}

ねえ、ここで C++ を初めて使用します。patientTypeプロジェクトに取り組んでいますが、検証が適切に機能しない理由がわかりません。私は最初に二重引用符を持っていましたが、それが文字列を表すことに気付きました。私はそれらを一重引用符に変更しました。私のプログラムは今すぐコンパイルして実行されますが、while ループは、I、i、O、o など、何を入力しても実行されます。

while ループが条件をチェックしていない理由がわかりません。条件に文字の 1 つを入力し、cout に進みました。単純なミスかもしれませんがよろしくお願いします。

4

3 に答える 3