I have my code but having trouble with calcultaion

closed account (D4NbpfjN)
I have a code but i am having trouble with the calculation part.
The local t-shirt shop sells shirts that retail for $12. Quantity dis-
counts are given as follow:

Number of Shirts Discount
5–10 10%
11–20 15%
21–30 20%
31 or more 25%
Write a program that prompts the user for the number of shirts required
and then computes the total price. Make sure the program accepts only
nonnegative input.
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
 #include<iostream>
#include<iomanip>
using namespace std;
int main()
{
	const double price = 12.00;
	double newprice = 0;
	double discount1 = 0.1;
	double discount2 = 0.15;
	double discount3 = 0.2;
	double discount4 = 0.25;

	int amount;

	cout << "How many shirts would you like?";
		cin >> amount;
		if (amount < 0)
			cout << "Invalid Input: Please enter a nonnegative integer\n";

	if (amount >= 5 && amount <= 10)
	{
		newprice = price - (price * discount1);
	}
		
	else if (amount >= 11 && amount <= 20)
	{
		newprice = price - (price * discount2);
	}
		
	else if (amount >= 21 && amount <= 30)
	{
		newprice = price - (price * discount3);
	}
		
	else if (amount >= 31)
	{
		newprice = price - (price * discount4);
	}
		
	else
	{
		newprice = price;
	}
	


	return 0;





}
add this snippet at the end of your code

1
2
3
cout<<"The new price of one shirt is : "<<newprice;

cout<<"\n\nThe amount to be paid for "<<amount<<"shirt is :  "<<newprice*amount;


you just calculated the discount for 1 shirt if you buy x shirts

by multiplying it by amount you will get the desired output
closed account (D4NbpfjN)
so where do i need to multiply the amount at?
here

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
if (amount >= 5 && amount <= 10)
	{
		newprice = price - (price * discount1);
	        newprice *= amount;
        }
		
	else if (amount >= 11 && amount <= 20)
	{
		newprice = price - (price * discount2);
	        newprice *= amount;
        }
		
	else if (amount >= 21 && amount <= 30)
	{
		newprice = price - (price * discount3);
	        newprice *= amount;
       }
		
	else if (amount >= 31)
	{
		newprice = price - (price * discount4);
                newprice *= amount;
	}
		
	else
	{
		newprice = price;
	        newprice *= amount;
        }


closed account (D4NbpfjN)
i put that on my code, but every time i enter the number of shirts it does not do the calculation. it just says press any key to continue.
could you show your whole code?
closed account (D4NbpfjN)
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
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
	const double price = 12.00;
	double newprice = 0;
	double discount1 = 0.1;
	double discount2 = 0.15;
	double discount3 = 0.2;
	double discount4 = 0.25;

	int amount;

	cout << "How many shirts would you like?";
		cin >> amount;
		if (amount < 0)
			cout << "Invalid Input: Please enter a nonnegative integer\n";

		if (amount >= 5 && amount <= 10)
		{
			newprice = price - (price * discount1);
			newprice *= amount;
		}

		else if (amount >= 11 && amount <= 20)
		{
			newprice = price - (price * discount2);
			newprice *= amount;
		}

		else if (amount >= 21 && amount <= 30)
		{
			newprice = price - (price * discount3);
			newprice *= amount;
		}

		else if (amount >= 31)
		{
			newprice = price - (price * discount4);
			newprice *= amount;
		}

		else
		{
			newprice = price;
			newprice *= amount;
		}
	


	return 0;





}
Hi,

You don't print out the result of your calculations !! The code is only going to do what you ask it to :+)

Could we ask you to please not start multiple topics about the same problem? It is ultimately a time waster for those who reply.
closed account (D4NbpfjN)

Here is my code so far. It is doing what i want it to except two things. The first one being when i enter the negative number it shows up invalid input what i wanted it to do, but it also shows up the retail price of the shirt and the final amount and it was -24. How do i get it not to do that. Another one is that if i type 8 shirts it comes up the regular retail price of 12 dollars instead of 10.80. If you look below this is the sample run i am suppose to be going by.

Sample Run 1:
How many shirts would you like?
4
The cost per shirt is $12 and the total cost is $48
Sample Run 2:
How many shirts would you like?
0
The cost per shirt is $12 and the total cost is $0

Sample Run 3:
How many shirts would you like?
8
The cost per shirt is $10.80 and the total cost is $86.40

Sample Run 4:
How many shirts would you like?
-2
Invalid$Input: Please enter a nonnegative integer


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
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
	const double price = 12.00;
	double newprice = 0;
	double discount1 = 0.1;
	double discount2 = 0.15;
	double discount3 = 0.2;
	double discount4 = 0.25;

	int amount;

	cout << "How many shirts would you like?";
		cin >> amount;
		
		if (amount < 0)
			cout << "Invalid Input: Please enter a nonnegative integer\n";

		if (amount >= 5 && amount <= 10)
		{
			newprice = price - (price * discount1);
			newprice *= amount;
		}

		else if (amount >= 11 && amount <= 20)
		{
			newprice = price - (price * discount2);
			newprice *= amount;
		}

		else if (amount >= 21 && amount <= 30)
		{
			newprice = price - (price * discount3);
			newprice *= amount;
		}

		else if (amount >= 31)
		{
			newprice = price - (price * discount4);
			newprice *= amount;
		}

		else
		{
			newprice = price;
			newprice *= amount;
		}
	
		
		cout << "The retail price per shirt is $" << price << endl;
		cout << "The new price of one shirt is $" << newprice;


	return 0;





}
Please don't post the same problem in multiple threads.
http://www.cplusplus.com/forum/beginner/192368/

It wastes everybody's time.
closed account (D4NbpfjN)
okay sorry about that
Topic archived. No new replies allowed.