*I need help solving this. Stuck half way. Would someone mind giving me an example of their program of this?*

The local t-shirt shop sells shirts that retail for \$12. Quantity discounts are given as follows:

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 non-negative input.

Use the following sample runs to guide you:

Sample Run 1:
How many shirts would you like?
11

The cost per shirt is \$10.20 and the total cost to you is \$112.20.

Sample Run 2:
How many shirts would you like?
0

The cost per shirt is \$12 and total cost to you is \$0.

Sample Run 3:
How many shirts would you like?
-2

invalid input: this program only accepts non-negative numbers.

Sample Run 4:
How many shirts would you like?
4
The cost per shirt if \$12 and total cost to you is \$48.00.

>> need help solving this. Stuck half way

Post what you have done so far. We don't do people's homework.

Use this to get started. And yes, please post your half of the code.

``````#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

float round (float number)
{
if(number < 0)

cout << "invalid input: this program only accepts non-negative numbers."; return 0;

{
if (number >=4 && <= 11)
{
cout << "" << endl;
}
else if (number >=10 && number <= 21)
{
cout << "" << endl;
}
else (number >=20 && number <= 31);
{
cout << "" << endl;
}
else (number >=31);
{
cout << "" << endl;
}

float model (int number, float cost)
{
float total, value, discount;

value = discount * cost;
discount = cost – DISCOUNT;
total =  number * discount;

return (total);
}

int main()

{

int shirt;
float total, cost, shirtTotal;

cout << "How many shirts would you like?";
cin  >> shirts;
cost = 12.00;
shirtTotal = model(shirt, cost);
cout << "The cost per shirt if \$12 and total cost to you is: " << shirtTotal << endl;
return 0;
}``````

*This is what I have so far. I don't know how to apply the discounts. Also, I'm quite new at this, I wouldn't mind if you're harsh at my coding xDD

When posting code, please wrap it with code tags.

``````if (number >=4 && <= 11)
{
cout << "" << endl;
}``````

Add 'number' to that check again, so it looks like

``````if (number >=4 && number <= 11)
{
cout << "" << endl;
}``````

Within your if statements, maybe you should determine the discount there. For example,

``````if (number >=4 && number <= 11)
{
discount = .10;
}``````

Then before you return from the function, you can use the discount to calculate the final cost.
Try compiling your code - I see a lot of things in your code that would give you compile errors. These compile errors should help you clean up a lot of your mistakes (e.g., calling 'model()' when you mean to call 'round()', etc. etc.)

OHHH alright thank you!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.