2013-10-08 59 views
-3

我想为学校写一个简单的程序,我有点问题。我必须输入两次才能正常工作。 例如我有输入3两次,它给我90 .. 我能做些什么来解决它。 此刻为什么我必须输入两次?

#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;    
} 
+0

请格式化您的代码;如果我们无法阅读它,那么我们无法帮助您(加上编写可读代码是必要技能)。 –

回答

4

是否编码看正确的,因为你有一个失踪的大括号。

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

    cin>>miles; 

尽管它是缩进的,“cin >>英里”;语句总是执行,它不是以else为条件的。

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

    cin>>miles; 
} 

会解决它。

+0

谢谢你。这很简单。我感觉很傻 – user2857087

+0

@ user2857087大家都这么做哈哈 – OMGtechy

相关问题