“Id返回1退出状态”错误c ++

时间:2015-09-17 03:35:45

标签: c++

我正在写这个相当简单的代码,但突然我开始得到这个“Id返回1退出状态错误”。我对此代码所做的最新更改是在显示功能中添加了所有“endl”。我不知道该怎么办,请帮忙

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

void getOrder(double&spools, double&stock, double&charge);
void displayOrder(double spools, double stock, double charge);


int main()
{
    double spools;
    double stock;
    double charge;
    getOrder(spools, stock, charge);
    displayOrder(spools, stock, charge);
    system("pause");//come back to these v2v lines
    return 0;   
}

void getOrder(double&spools, double&stock, double&charge)
{
    charge= 0;
    char extra;
    double extraCharge;
    cout<<"How many spools were ordered?:";
    cin>>spools;
    while(spools<1){
        cout<<"Entry must be greater than 1...: ";
        cin>> spools;
    }
    cout<<"How many spools are in stock?:";
    cin>>stock;
    while(stock<0){
        cout<<"Entry must be greater than 0...: ";
        cin>> stock;
    }
    cout<<"Are there any special shipping and handling chsrges?(y for yes, n for no):";
    cin>>extra;
    if(extra=='y'|| extra=='Y'){
        cout<<"Enter the special charge amount:$";
        cin>>extraCharge;
        while(extraCharge<0){
        cout<<"Entry must be greater than 0... :";
        cin>> extraCharge;
        }
    }

    charge=extraCharge;
//no returns needed because reference variables 
}

void displayOrder(double spools, double stock, double charge=10)
{
    double backOrder=spools-stock;
    double spoolsOrdered;
    double subTotal=spools*100;
    double shipping;
    double total=subTotal+charge;
    double ready=stock-spools;

    //spools ready to ship from current stock
    cout<<"There are"<<ready<<"spools ready to be shipped."<<endl;
    //if statement for BACKORDERRRrr
    if(spools>stock)
    {
        backOrder=spools-stock;
        cout<<"There are"<<ready<<"spools ready to be shipped."<<endl;
        cout<<"There are"<<backOrder<<"spools on back order."<<endl;
        cout<<"Subtotal: $"<<subTotal<<endl;
        cout<<"Shipping & Handling charge:$"<<charge<<endl;
        cout<<"The total fee for this transaction is:$"<<total<<endl;

    }
    else
    {
        cout<<"There are"<<ready<<"spools ready to be shipped."<<endl;
        cout<<"Subtotal: $"<<subTotal<<endl;
        cout<<"Shipping & Handling charge:$"<<charge<<endl;
        cout<<"The total fee for this transaction is:$"<<total<<endl;
    }
}

1 个答案:

答案 0 :(得分:1)

我刚刚在Dev C ++上尝试了你的代码,它运行得非常好。 此错误的可能原因是上一次运行的.exe文件仍然在某处。关闭它然后再试一次。