程序无法正常工作的解决方案

时间:2013-11-21 15:29:51

标签: c++

我的程序有问题。我的代码可以运行,但有些东西导致它停止工作。我已多次检查程序,但我看不出问题。感谢任何帮助我的人。真的很感激。

#include <iostream>
#include <string>

using namespace std;

double getdiscount(int customer_city, double gal_last)

{
     getdiscount(customer_city, gal_last);
    return 0;
}


int main()
{
    int customer_city ;
    double gal_last, gal_bought, price_per_gal, discount, tot_cost;

    cout << " The number of gallon being purchased in gal: " << endl;
    cin >> gal_bought;

    cout << " The price per gallon you bought : "<<"RM";
    cin >> price_per_gal;

    cout<<" Enter customer city : "<<endl;
    cin>>customer_city;

    cout<<" Number of gallons of oil used last year : " <<endl;
    cin>>gal_last;

    switch (customer_city)

    {
    case 1:
        (customer_city == 1);
        if (gal_last>=1000)
            discount = 0.9;
        else
            discount = 1;
        break;

    case 2:
        (customer_city == 2);
        (gal_last >=1200);
        discount = 0.9;
        break;

    default:
        if (gal_last >=1500)
            discount = 0.9;

        cout<< " Discount rate is : "<<discount<<endl;
    }

     tot_cost = gal_bought* (price_per_gal*getdiscount(customer_city, gal_last) );

    cout<< " The total cost : "<<tot_cost<<endl;

    return 0;
} //end main function

1 个答案:

答案 0 :(得分:4)

这是递归调用自己......

double getdiscount(int customer_city, double gal_last)

{
     getdiscount(customer_city, gal_last);
    return 0;
}

直到你得到一个stackoverflow ...