-3

学校向けの簡単なプログラムを書こうとしていますが、少し問題があります。正しく機能させるには、2 回入力する必要があります。たとえば、90 を得るために 3 を 2 回入力しました。修正するにはどうすればよいですか。コーディングは現時点で正しく見えますか

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

int main(){
    string Cartype, rateoption;
    double total, miles, days;
    const double CdailyRate=30;
    const double PdailyRate=40;
    const double FdailyRate=50;
    const double CmileRate=0.25;
    const double PmileRate=0.35;
    const double FmileRate=0.45;

    cout<<"Thank you for choosing Car Rite Rental for your rental needs!\n"
    <<"\a Before we get started calculating your total owed please remember\n"
    <<"that here at Car Rite Rental we havea MINIMUM PAYMENT OF $30.\n\n"
    <<"Please enter the type of car you have rented: \n\n"
    <<"[please enter corresponding letter] \n"
    <<"C-Chevrolet\n"<<"P-Pontiac\n"<<"F-Ford\n";
    cin>>Cartype;
    cout<<"Please choose your payment option from the following: \n\n"
    <<"[please enter corresponding number] \n"
    <<"D-Daily Rate\n"<<"M-Mileage Rate\n";
    cin>>rateoption;

    if(rateoption=="D"||rateoption=="d"){
        cout<<"Please enter the number of days you have rented this vehicle: \n";
        cin>>days;
    }
    else
        cout<<"Please enter the number of miles traveled in your rental car:\n";

        cin>>miles;

    if (Cartype=="C"||Cartype=="c" && rateoption=="D"||rateoption=="d"){
        total=CdailyRate*days;
        cout<<"Your total owed today is: $"<<total<<"\nThank you again for choosing Car Rite Rental!\n";
    }

    return 0;            
}
4

1 に答える 1

4

中括弧のセットが欠落しているためです。

else
    cout<<"Please enter the number of miles traveled in your rental car:\n";

    cin>>miles;

インデントされていますが、「cin>>miles;」ステートメントは常に実行され、else の条件付きではありません。

else {
    cout<<"Please enter the number of miles traveled in your rental car:\n";

    cin>>miles;
}

それを修正します。

于 2013-10-08T05:21:13.300 に答える