Question
Program 4 - On Sale With the holidays over stores across America are putting their unsold items on sale. Create a double Array of size
Program 4 - On Sale
With the holidays over stores across America are putting their unsold items on sale.
Create a double Array of size 10. Populate the Array with random numbers between 0 and 2000. We will then print the numbers in the Array, all on the same line while using a fixed precision with 2 decimal places. Use the following code: A $ sign will be a nice addition. Name your program: OnSale
Here is an example how to format your output to 2 decimal places.
Add this include statement to your code:
#include
//Set the number of decimal places to 2 cout << setprecision(2) << fixed;
Change the values in the Array as such:
If the item cost $5.00 or less increase the cost by 8%. If the items cost greater than $5.00 but not more than $10.00 increase the cost by 6%. If the item cost more than $10.00 but not more than $16.00 increase the cost by 4%. If the item cost more than $16.00 decrease the cost by 2%.
Print the Array using the fixed precision as above.
Here is some starter code to help you along.
******************************************************************
#include
using namespace std;
int randRange(int low, int high){ return rand() % (high - low + 1) + low; }
int main(){ srand(time(NULL)); double myArray[10];
//Set the number of decimal places to 2 cout << setprecision(2) << fixed;
//Create Array of 10 random int numbers for (int i = 0; i < 10; i++) { myArray[i] = randRange(0, 2000) / 100.0; }
//Write the code to complete the changes and print the Array. }
*************************************************************************
Here is a sample of what the output should look like:
$4.78, $11.98, $9.87, $3.81, $9.61, $13.89, $6.09, $5.61, $13.50, $4.94,
$5.16, $12.46, $10.46, $4.11, $10.19, $14.45, $6.46, $5.95, $14.04, $5.34,
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started