Need help on code

Hi!

I've made the code bellow in order to meet the following criteria:

5 - Supplier has 0 (zero) claims.
4 - Supplier has claims but his performance is bellow both targets( Supplier Target and Teorical Target).
3 - Supplier has claims but but has reached one of the targets.
2 - Supplier has claims but his performance didn't exceed in more than 30% the highest target.
1 - Supplier has claims but his performance has exceeded in more than 30% both targets.

The code bellow compiles without errors but when I test it with a supplier evaluated as 1 (Very Bad), the program reaches the end without giving me any result.
I would like to ask for your help because I've spent all day trying to find the problem without any success.

Thanks

Rui



===========================================================
// CODE

#include
#include


int GetBig(float x, float y) //Global function: find biggest value (theoretical, practical)
{
if (x < y) return 2; // Theory is bigger
else if(x > y) return 1; // Practical is bigger
else return 0;
}

int main()
{
int vehicles;
int claims;
float practical;
float theoretical;



cout << "Please input the Claims Qty." << endl;
cin >> claims;

cout << "Please input the Supplier Target" << endl;
cin >> practical;

cout << "Please input the Theoretical Target" << endl;
cin >> theoretical;

cout << "Please input the n of vehicles produced" << endl;
cin >> vehicles;

const float performance = static_cast(claims)/static_cast(vehicles);

if (claims == 0)
{
cout << "Supplier was evaluated as 5 (Excellent)" << endl;
}
else
{
if (performance < theoretical && performance < practical)
{
cout << "Supplier was evaluated as 4 (Good)" << endl;
}
else
{
if (performance < theoretical || performance < practical)
{
cout << "Supplier was evaluated as 3 (Regular)" << endl;
}
else
{
if (int WhichBig = GetBig(practical, theoretical) )

{
switch (WhichBig)
{
case 2: if (performance < theoretical*1.3)
{
cout << "Supplier was evaluated as 2 (Bad)" << endl;
} break;

case 1: if (performance < practical*1.3)
{
cout << "Supplier was evaluated as 2 (Bad)" << endl;
} break;

}
}
else //Line 67
{
if (performance > WhichBig*1.3)
{
cout << "Supplier was evaluated as 1 (Very Bad)" << endl;
}
}
}
}
}

system("PAUSE"); //Line 84
return 0; //Line 85
}

===========================================================

Comments

  • Hello
    i am not too sure what is happening in this program and i haven't got the time at the moment to go through it properly, but i have marked a few (3) lines of code with (*)'s. try deleting these lines and see if that makes a difference. Hope this helps.
    If it doesn't let me know and i will try and spend some time looking.
    :
    :
    : ===========================================================
    : // CODE
    :
    : #include
    : #include
    :
    :
    : int GetBig(float x, float y) //Global function: find biggest value (theoretical, practical)
    : {
    : if (x < y) return 2; // Theory is bigger
    : else if(x > y) return 1; // Practical is bigger
    : else return 0;
    : }
    :
    : int main()
    : {
    : int vehicles;
    : int claims;
    : float practical;
    : float theoretical;
    :
    :
    :
    : cout << "Please input the Claims Qty." << endl;
    : cin >> claims;
    :
    : cout << "Please input the Supplier Target" << endl;
    : cin >> practical;
    :
    : cout << "Please input the Theoretical Target" << endl;
    : cin >> theoretical;
    :
    : cout << "Please input the n of vehicles produced" << endl;
    : cin >> vehicles;
    :
    : const float performance = static_cast(claims)/static_cast(vehicles);
    :
    : if (claims == 0)
    : {
    : cout << "Supplier was evaluated as 5 (Excellent)" << endl;
    : }
    : else
    : {
    : if (performance < theoretical && performance < practical)
    : {
    : cout << "Supplier was evaluated as 4 (Good)" << endl;
    : }
    : else
    : {
    : if (performance < theoretical || performance < practical)
    : {
    : cout << "Supplier was evaluated as 3 (Regular)" << endl;
    : }
    : else
    : {
    : if (int WhichBig = GetBig(practical, theoretical) )
    :
    : {
    : switch (WhichBig)
    : {
    : case 2: if (performance < theoretical*1.3)
    : {
    : cout << "Supplier was evaluated as 2 (Bad)" << endl;
    : } break;
    :
    : case 1: if (performance < practical*1.3)
    : {
    : cout << "Supplier was evaluated as 2 (Bad)" << endl;
    : } break;
    :
    : }
    : }
    : else //Line 67
    : {
    : if (performance > WhichBig*1.3) **************************
    : { **************************
    : cout << "Supplier was evaluated as 1 (Very Bad)" << endl;
    : } **************************
    : }
    : }
    : }
    : }
    :
    : system("PAUSE"); //Line 84
    : return 0; //Line 85
    : }
    :
    : ===========================================================
    :

  • Hello Again

    After about 2 hours i think i have finally managed to find out why it doesn't work. I haven't written it out properly because my brain is hurting. (Its a confusing program). I will explain it instead.

    This is the code for the bit that doesn't work:-

    if (performance > WhichBig*1.3)
    {
    cout << "Supplier was evaluated as 1 (Very Bad)" << endl;
    }

    The function WhichBig() is always going to return 1, 2 or 0, so that means that the the possible values for WhichBig*1.3 are 1.3, 2.6 and 0.
    Aghhhhhhhh. Sorry, too much coffee. I have confused myself again. Here is what you have to do.

    like what you did for 2(Bad) with the case thing but change the arrow thing(<) the other way round(>) for both of them. and it should hopefully work!! if not then i am very sory but i haven't got a clue.
    Hope this helps.
    Now, where's my coffe gone?
  • : Hi!
    :
    : I've made the code bellow in order to meet the following criteria:
    :
    : 5 - Supplier has 0 (zero) claims.
    : 4 - Supplier has claims but his performance is bellow both targets( Supplier Target and Teorical Target).
    : 3 - Supplier has claims but but has reached one of the targets.
    : 2 - Supplier has claims but his performance didn't exceed in more than 30% the highest target.
    : 1 - Supplier has claims but his performance has exceeded in more than 30% both targets.
    :
    Finally I finished it and now it works OK.

    Thanks

    Rui
    :
    :
    :
    : ===========================================================
    : // CODE
    :
    #include
    #include


    float GetBig(float x, float y) //Global function: find biggest value (theoretical, practical)
    {
    if (x < y) return y; // Theory is bigger
    else if(x > y) return x; // Practical is bigger
    else return 0;
    }

    int main()
    {
    int vehicles;
    int claims;
    float practical;
    float theoretical;



    cout << "Please input the Claims Qty." << endl;
    cin >> claims;

    cout << "Please input the Supplier Target" << endl;
    cin >> practical;

    cout << "Please input the Theoretical Target" << endl;
    cin >> theoretical;

    cout << "Please input the n of vehicles produced" << endl;
    cin >> vehicles;

    const float performance = static_cast(claims)/static_cast(vehicles);

    float WhichBig = GetBig(practical, theoretical);

    if (claims == 0)
    {
    cout << "Supplier was evaluated as 5 (Excellent)" << endl;
    }
    else
    {
    if (performance < theoretical && performance < practical)
    {
    cout << "Supplier was evaluated as 4 (Good)" << endl;
    }
    else
    {
    if (performance < theoretical || performance < practical)
    {
    cout << "Supplier was evaluated as 3 (Regular)" << endl;
    }
    else
    {
    if (performance < WhichBig*1.3)
    {
    cout << "Supplier was evaluated as 2 (Bad)" << endl;
    }
    else
    {
    if (performance > WhichBig*1.3)
    {
    cout << "Supplier was evaluated as 1 (Very Bad)" << endl;
    }
    }
    }
    }
    }

    system("PAUSE"); //Line 84
    return 0; //Line 85
    }
    :
    : ===========================================================
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories