i have one homework, but they do not explan arrays.
a. Declare an PRODUCT_COUNT constant to store the number of products purchased in-store.
b. Declare a PRODUCT_COUNT array of prices to store product prices - without initializing it
c. Enter prices from the console by writing them in the prices array.
d. Declare an integer constant DISCOUNT_COUNT by initializing it with zero
e. Reduce all prices greater than $ 10 by 5% (write down the reduced prices in the prices array) and in the DISCOUNT_COUNT variable register the number of reduced products
f. Display the new product prices and the number of discounted products.
due to the quarantine itself we had a connection problem, and she decide to give us this task.
I did somethink but i dont know is it right.
It's not that much, and its not right ..
#include <iostream>
using namespace std;
int main () {
#include <iostream>
usingnamespace std;
int main()
{
constexpr size_t PRODUCT_COUNT{ 10 }; // <--- a.
constexprdouble DISCOUNT_COUNT{}; // <--- fulfills d, but can not be used or changed.
double product_count[PRODUCT_COUNT]; // <--- b. But what will be stored here?
double prices[PRODUCT_COUNT];
for (int i = 0; i < PRODUCT_COUNT; i++)
{
cout << "Enter prices: " << endl; // <--- c.
cin >> prices[i];
}
// <--- e and f.
return 0; // <--- Not required, but makes a good break point.
}
I would call this a start, but it still needs some work.
The for loop will iterate 10 times even if you do not have 10 items to enter. Although this could work if the "prices" array is not initialized.
I have to say that the instructions can be taken in 2 different ways. Not being in the class to here what lead up to this assignment I am not sure what is expected.