Can you help me with this

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.

thanks
Last edited on
> i have one homework, but they do not explan arrays.
Why haven't they?

> i've done a and b.
That would mean you know something about arrays then.

Post your code, make a guess as to what c might look like and then we'll help.

Just dumping your assignment with no demonstrated effort to solve the problem will generally get you ignored.
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 () {



double prices [4];
for (int i=0; i<4; i++) {
cout<<"Enter prices: "<<endl;
cin>>prices [i];
}


}
PLEASE learn to use code tags, they make reading and commenting on source code MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/

HINT: you can edit your post and add code tags.
Hello gVd9,


PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

Along with the proper indenting it makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button, but you may still to indent your code.

You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.


Trying to follow the instructions I came up with this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

using namespace std;

int main()
{
	constexpr size_t PRODUCT_COUNT{ 10 };  // <--- a.
	constexpr double 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.

Andy
Topic archived. No new replies allowed.