Issue with a while loop

So I am writing a simple while loop program that calculates a discount for a number of shirts a person enters into the program. For the most part it works, however I am getting a strange value if I enter in the same value multiple times:

Input value: 4 Price of shirts are $12.00 and total value is $48.00
Input value: 4 Price of shirts are $9.00 and total value is $36.00
Input value: 4 Price of shirts are $12.00 and total value is $48.00
Input value: 4 Price of shirts are $9.00 and total value is $36.00

This is exactly what I see in the command window.

My code is below:

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
#include<iostream>
#include<iomanip>
#include<math.h>

using namespace std;

int main()
{
	int number;
	double total_price, new_price;
	const double shirt_price = 12.00;

	cout << "Number of Shirts Discount.\n";
	cout << "5 to 10 shirts: 10% Discount.\n";
	cout << "11 to 20 shirts: 15% Discount.\n";
	cout << "21 to 30 shirts: 20% Discount.\n";
	cout << "31 or more shirts: 25% Discount.\n";

	cout << "\nHow many shirts would you like? ";
	cin >> number;

	cout << showpoint << setprecision(4);

	while (number >= 0) {   //For all 0 or positive values

		if (number <= 4) {    //Price for 0 to 4 shirts
			new_price = shirt_price;
			total_price = new_price * number;
			cout << "The cost per shirt is $12 and the total cost is $ " << total_price << endl;
			cout << "\nHow many shirts would you like? ";
			cin >> number;	}

		else if (number = 5 && number <= 10) {    //Price for 5-10 shirts
			new_price = shirt_price - (shirt_price * .1);
			total_price = new_price * number;
			cout << "The cost per shirt is $ "<< new_price << " and the total cost is $ " << total_price << endl;	
			cout << "\nHow many shirts would you like? ";
			cin >> number; 	}

		else if (number >= 11 && number <= 20) {    //Price for 11-20 shirts
			new_price = shirt_price - (shirt_price * .15);
			total_price = new_price * number;
			cout << "The cost per shirt is $ " << new_price << " and the total cost is $ " << total_price << endl;
			cout << "\nHow many shirts would you like? ";
			cin >> number;	}

		else if (number >=21 && number <= 30) {    //Price for 21-30 shirts
			new_price = shirt_price - (shirt_price * .2);
			total_price = new_price * number;
			cout << "The cost per shirt is $ " << new_price << " and the total cost is $ " << total_price << endl;				
			cout << "\nHow many shirts would you like? ";
			cin >> number;	}

		else (number >= 31); {   //Price for 31+ shirts
			new_price = shirt_price - (shirt_price * .25);
			total_price = new_price * number;
			cout << "The cost per shirt is $ " << new_price << " and the total cost is $ " << total_price << endl;
			cout << "\nHow many shirts would you like? ";
			cin >> number; }

		}

	cout << "\nInvalid number.  Please run program again.\n";  //End program if negative value is entered.

	system("pause");
	return 0;

}


This is my first coding class and I am doing online classes. Any and all help and teaching is greatly appreciated!
check your else if statement on line 33

else if (number = 5 && number <= 10)

I assume you want this
else if (number >= 5 && number <= 10)
Last edited on
I have tried that in my code but I still get the same results.
Line 54: Remove the ; The ; makes the following statements unconditional.
Topic archived. No new replies allowed.