dimanche 2 octobre 2016

Can anyone help me figure out the issue in my code?

#include <iostream>

using namespace std;

int main()

{

  int tariff,number_units;


cout<<"Enter the tariff number from 110,120 and 140\n";


  cout<<"Choice:";

  cin>>tariff;


  cout<<"Enter the number of units:";

  cin>>number_units;


  float Minimum_charge,first25,next50,next75,remaining;


  switch (tariff)

  {

  case 110:

    Minimum_charge=44.00;

    first25=2.75;

    next50=3.25;

    next75=4.00;

    remaining=6.50;



    break;

  case 120:

    Minimum_charge=184.00;

    first25=3.00;

    next50=3.50;

    next75=4.25;

    remaining=6.00;

    break;

  case 140:

    Minimum_charge=360.00;

    first25=3.25;

    next50=3.75;

    next75=4.50;

    remaining=5.75;


    break;

  default:

    cout<<"You did not enter one of 110,120 or 140!"<<endl;

    break;

  }
    float total;


    if (tariff==110)

    {


       if (number_units<=25)

        {
            total=((Minimum_charge)+(first25*number_units));

        }


        if (number_units<=70)

        {

            total=((number_units-25)*next50);

        }


        if (number_units<=150)

        {

            total=((number_units-75)*next75);

        }


        if (number_units>150)

        {

            total=((number_units-150)*remaining);

        }

    }

    else if (tariff==120)

    {

        if (number_units<=25)

        {

            total=((Minimum_charge) + (first25*number_units));

        }


        if (number_units<=70)

        {

            total=((number_units-25)*next50);

        }


        if (number_units<=150)

        {

            total=((number_units-75)*next75);

        }


        if (number_units>150)

        {

            total=((number_units-150)*remaining);

        }

    }


    else if(tariff==140)

    {



         if (number_units<=25)

        {

            total=((Minimum_charge)+(first25*number_units));

        }


        if (number_units<=70)

        {

            total=((number_units-25)*next50);

        }


        if (number_units<=150)

        {

            total=((number_units-75)*next75);

        }



        if (number_units>150)

        {

            total=((number_units-150)*remaining);

        }

    }


    else

    {

        cout<<"You enter the wrong tariff number!"<<endl;

    }


    cout<<"The total fee to be paid is: "<<total<<endl;


    return 0;


  }

Question for the code

Aucun commentaire:

Enregistrer un commentaire