mercredi 27 septembre 2017

C++ if else logical errors and incorrect output

i would like to ask which logical error am i facing? Even though i enter number 1 for every type of CD , the output will have 5% discount .. 5% discount is only for 2 to 5 purchases of CD

#include <iostream>
using namespace std;

int main() {
    int type_i,type_l,type_o,type_c;
    float cost_i,cost_l,cost_o,cost_c,discount_i,discount_l,discount_o,discount_c,discounted_i,discounted_l,discounted_o,discounted_c,total_dis,amount;
    float price_i=39.9,price_l=29.9,price_o=49.9,price_c=59.9;

    cout<<"\t\t\tPower House\n";
    cout<<"Quantity of International CD:";
    cin>>type_i;
    cout<<"Quantity of Local CD:";
    cin>>type_l;
    cout<<"Quantity of Oldies CD:";
    cin>>type_o;
    cout<<"Quantity of Classic CD:";
    cin>>type_c;

    cost_i=type_i*price_i;
    cost_l=type_l*price_l;
    cost_o=type_o*price_o;
    cost_c=type_c*price_c;

    if (2<=type_i<=5){

        discount_i=cost_i*0.05;
        discounted_i=cost_i*0.95;
        }
        else if(6<=type_i<=10){

            discount_i=cost_i*0.1;
            discounted_i=cost_i*0.9;
        }
        else if(11<=type_i<=15){

            discount_i=cost_i*0.15;
            discounted_i=cost_i*0.85;
        }
        else if(16<=type_i<=20){

            discount_i=cost_i*0.2;
            discounted_i=cost_i*0.8;
        }
        else if(type_i>20){

            discount_i=cost_i*0.25;
            discounted_i=cost_i*0.75;
        }
        else if(0<=type_i<=1){
        discounted_i=cost_i;
    }
    if (2<=type_l<=5){

        discount_l=cost_l*0.05;
        discounted_l=cost_l*0.95;
        }
        else if(6<=type_l<=10){

            discount_l=cost_l*0.1;
            discounted_l=cost_l*0.9;
        }
        else if(11<=type_l<=15){

            discount_l=cost_l*0.15;
            discounted_l=cost_l*0.85;
        }
        else if(16<=type_l<=20){

            discount_l=cost_l*0.2;
            discounted_l=cost_l*0.8;
        }
        else if(type_l>20){

            discount_l=cost_l*0.25;
            discounted_l=cost_l*0.75;
        }
        else if(0<=type_l<=1){
        discounted_l=cost_l;
    }
    if (2<=type_o<=5){

        discount_o=cost_o*0.05;
        discounted_o=cost_o*0.95;
        }
        else if(6<=type_o<=10){

            discount_o=cost_o*0.1;
            discounted_o=cost_o*0.9;
        }
        else if(11<=type_o<=15){

            discount_o=cost_o*0.15;
            discounted_o=cost_o*0.85;
        }
        else if(16<=type_o<=20){

            discount_o=cost_o*0.2;
            discounted_o=cost_o*0.8;
        }
        else if(type_o>20){

            discount_o=cost_o*0.25;
            discounted_o=cost_o*0.75;
        }
        else if (0<=type_o<=1){
        discounted_o=cost_o;
    }
    if (2<=type_c<=5){

        discount_c=cost_c*0.05;
        discounted_c=cost_c*0.95;
        }
        else if(6<=type_c<=10){

            discount_c=cost_c*0.1;
            discounted_c=cost_c*0.9;
        }
        else if(11<=type_c<=15){

            discount_c=cost_c*0.15;
            discounted_c=cost_c*0.85;
        }
        else if(16<=type_c<=20){

            discount_c=cost_c*0.2;
            discounted_c=cost_c*0.8;
        }
        else if(type_c>20){

            discount_c=cost_c*0.25;
            discounted_c=cost_c*0.75;
        }
        else if(0<=type_c<=1){
        discounted_c=cost_c;
    }

    total_dis=discount_i+discount_l+discount_o+discount_c;
    amount=discounted_i+discounted_l+discounted_o+discounted_c;

    cout<<"Total discount:"<<total_dis;
    cout<<"\nAmount due:"<<amount;


}

http://ift.tt/2k3IHBD

^ above is my question for this program

Aucun commentaire:

Enregistrer un commentaire