IF STATEMENT QUESTION

Hi,everyone. May I know why the program only solve using the 1st "if" statement? For example, I insert 10 into "quantityOfT", and it is supposed to use
"else if (6<=quantityOfT<=10){
discountOfT= t*0.1*quantityOfT;"

, but it used "if (2<=quantityOfI<=5){
discountOfI= i*0.05*quantityOfI;"
instead.
Is my program having errors in the first place? and may I know what is the eroor causing this situation? Thank you very much in advance!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include<iostream>
using namespace std;

int main(){
	double i,t,o,c,totalDiscount,amountDue, quantityOfI,quantityOfT,quantityOfO,quantityOfC,discountOfI,discountOfT,discountOfO,discountOfC;
	double amountDueOfI,amountDueOfT,amountDueOfO,amountDueOfC;
	i=39.9;
	t=29.9;
	o=49.9;
	c=59.9;
	
	
    
	
	cout<<"Please insert the quantity of I"<<endl;
	cin>>quantityOfI;
	if (2<=quantityOfI<=5){
		discountOfI= i*0.05*quantityOfI;
	}
	else if (6<=quantityOfI<=10){
		discountOfI= i*0.1*quantityOfI;
	}
	else if (11<=quantityOfI<=15){
		discountOfI=i*0.15*quantityOfI;
	}
	else if (16<=quantityOfI<=20){
		discountOfI=i*0.2*quantityOfI;
	}
	else if (quantityOfI>=21){
		discountOfI=i*0.25*quantityOfI;
	}
	else {
		cout<<"pleasr type again."<<endl;
	}
	amountDueOfI = (i*quantityOfI)-discountOfI;
	cout<<"Discount is "<<discountOfI<<endl;
	cout<<"Amount is "<<amountDueOfI<<endl;
		
		
	cout<<"Please insert the quantity of T"<<endl;
	cin>>quantityOfT;
	if (2<=quantityOfT<=5){
		discountOfT= t*0.05*quantityOfT;
	}
	else if (6<=quantityOfT<=10){
		discountOfT= t*0.1*quantityOfT;
	}
	else if (11<=quantityOfT<=15){
		discountOfT=t*0.15*quantityOfT;
	}
	else if (16<=quantityOfT<=20){
		discountOfT=t*0.2*quantityOfT;
	}
	else if (quantityOfT>=21){
		discountOfT=t*0.25*quantityOfT;
	}
	else {
		cout<<"pleasr type again."<<endl;
	}
	amountDueOfT = (t*quantityOfT)-discountOfT;
	cout<<"Discount is "<<discountOfT<<endl;
	cout<<"Amount is "<<amountDueOfT<<endl;
	
	
	cout<<"Please insert the quantity of O"<<endl;	
	cin>>quantityOfO;
	if (2<=quantityOfO<=5){
		discountOfO= o*0.05*quantityOfO;
	}
	else if (6<=quantityOfO<=10){
		discountOfO= o*0.1*quantityOfO;
	}
	else if (11<=quantityOfO<=15){
		discountOfO=o*0.15*quantityOfO;
	}
	else if (16<=quantityOfO<=20){
		discountOfO=o*0.2*quantityOfO;
	}
	else if (quantityOfO>=21){
		discountOfO=o*0.25*quantityOfO;
	}
	else {
		cout<<"pleasr type again."<<endl;
	}
	amountDueOfO = (o*quantityOfO)-discountOfO;
	cout<<"Discount is "<<discountOfO<<endl;
	cout<<"Amount is "<<amountDueOfO<<endl;
	
	cout<<"Please insert the quantity of C"<<endl;	
		cin>>quantityOfC;
	if (2<=quantityOfC<=5){
		discountOfC= c*0.05*quantityOfC;
	}
	else if (6<=quantityOfC<=10){
		discountOfC= c*0.1*quantityOfC;
	}
	else if (11<=quantityOfC<=15){
		discountOfC=c*0.15*quantityOfC;
	}
	else if (16<=quantityOfC<=20){
		discountOfC=c*0.2*quantityOfC;
	}
	else if (quantityOfC>=21){
		discountOfC=c*0.25*quantityOfC;
	}
	else {
		cout<<"pleasr type again."<<endl;
	}
	amountDueOfC = (c*quantityOfC)-discountOfC;
	cout<<"Discount is "<<discountOfC<<endl;
	cout<<"Amount is "<<amountDueOfC<<endl;
		
totalDiscount = discountOfI + discountOfT + discountOfO + discountOfC;
amountDue = amountDueOfI + amountDueOfT + amountDueOfO + amountDueOfC;

	cout<<"The total discount is "<<totalDiscount<<endl;
	cout<<"The amount due is "<<amountDue<<endl;
	
	return 0;
 
}
a <= x <= b doesn't do what you think. The correct way to write what you mean is a <= x && x <= b.
Wow. Thank you very much!
Topic archived. No new replies allowed.