How can i change specific elements of an array?

Hello all!
In the exercise that I'm working on it asks that I write an input statement that will allow the user to enter values for specific elements. here my code that lets users enter values for all elements

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main()
{
	// Constant Declarations
	const int SIZE = 10;
	
	// Variable Declarations
	double prices[SIZE];
	double total;
	
	total = 0;
	cout << fixed << setprecision(2);
	// Allow the user to enter all prices:
	for(int i = 0; i < SIZE; i++)
	{
		cout << "Enter the price of Product " << i + 1 << ": $";
		cin >> prices[i];
	}
	


My question is how can alter my code to let users change specific elements of the array. say I wanted to make it so can enter values for the first, seventh, and third elements?

any example would be greatly appreciated.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>

int main()
{
	int a[10];
	int b, c;

	std::cout << "Enter Index: ";
	std::cin >> b;
	std::cout << "Enter Value: ";
	std::cin >> c;

	a[b] = c;
}


You'd loop through similar code in order to have the user be able to change multiple elements.

There are other ways, what are you trying to achieve?
Last edited on
Topic archived. No new replies allowed.