Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.

Error Detection

Abdelrhman_M_
Beginner
144 Views

Hey I was writing a code and made an error detection but its not working can someone help me ?

void addShip()
{
    string custName,destName;
    int custID,destID,find,counter=0,shipID=1001;
    double shipCost,firstHalfKilo,addKilo,shipWeight;
    bool custIDExist=false,destIDExist=false;
    char yesOrNo;
    ifstream infile;
    ofstream outfile;


    while (counter==0)
    {
    cout<<"Enter your customer ID "<<endl;
    cin>>custID;
    cout<<"Enter your destination ID"<<endl;
    cin>>destID;
    cout<<"Enter the shipment weight"<<endl;
    cin>>shipWeight;

    infile.open("Shipment ID.txt");
    infile>>shipID;
    infile.close();

    infile.open("customers.txt");
    find=custID;
    while (infile>>custID>>custName)
    {
        custIDExist=false;
        if(find==custID)
        {
            custIDExist=true;
            break;
        }
    }

    infile.close();

    if (custIDExist==false)
    {
        cout<<"Error: Customer ID does not exist."<<endl;
        goto Error;
    }


    infile.open("Destinations.txt");
    find=destID;
    while(infile>>destID>>destName>>firstHalfKilo>>addKilo)
    {
        destIDExist=false;
        if(find==destID)
        {
            destIDExist=true;
            break;
        }
    }
    infile.close();

    
    if (destIDExist==false)
    {
        cout<<"Error: Destenation ID does not exist."<<endl;
        goto Error;
    }
    

    shipCost=firstHalfKilo+((shipWeight-0.5)*addKilo);
    

    outfile.open("shipments.txt",ios::app);
    outfile<<shipID<<"\t"<<custID<<"\t"<<destID<<"\t"<<shipWeight<<"\t"<<shipCost<<endl<<"\n";
    outfile.close();


    cout<<"Shipment ID: "<<shipID<<endl<<"================="<<endl;
    cout<<"Customer ID: "<<custID<<endl<<"Customer Name: "<<custName<<endl<<"================="<<endl;
    cout<<"Destination ID: "<<destID<<endl<<"Destination Name: "<<destName<<endl<<"================="<<endl;
    cout<<"Shipment Details: "<<endl<<"First Half Kilo"<<"\t\t"<<"Each Add. Kilo"<<"\t\t"<<"Shipment Weight"<<"\t\t"<<"Cost"<<endl;
    cout<<std::setprecision(5)<<firstHalfKilo<<"\t\t\t"<<std::setprecision(5)<<addKilo<<"\t\t\t"<<std::setprecision(5)<<shipWeight<<"\t\t\t"<<std::setprecision(5)<<shipCost<<endl;

    outfile.open("Shipment ID.txt");
    outfile<<++shipID;
    outfile.close();

    Error:
    cout<<"Do you want to enter new Shipment?\n "<<"enter ( Y ) for yes and ( N ) for no "<<endl;
                cin>>yesOrNo;
                switch(yesOrNo)
                {
                case'y':
                case'Y':
                    break;
                case'n':
                case'N':
                    counter++;
                    break;
                }
    
    }
}

0 Kudos
1 Reply
Anoop_M_Intel
Employee
144 Views

Hi Abdulrhman,

Could you please provide more info on what kind of help you are looking for?

1. Are you facing issues when using Intel C++ Compiler to build this program?
2. is the issue which you are talking about compiler time or run time issue?
3. What compiler options are you using?

Thanks and Regards
Anoop

Reply