+ 3

Arrays In Calculation C++

You are given an array of doubles of items in a store that have different prices (see template). Write a program that takes the "percent off" discount as input and outputs discounted item prices on one line in the same sequence you are given, separated by a space (" "). my code: int main() { double items[] = {500, 12.4, 94, 45, 3, 81, 1000.9, 85, 90, 1, 35}; double discount = 0; //your code goes here for (double x = 0; x < 11; x++){ cin >> discount; discount = items[x]-items[x]*discount/100; } cout << discount << endl; I don't understand how this won't calculate. I keep getting error that says "error: invalid types 'double [11][double]' for array subscript". I don't know what this means at all. I keep trying to google it but I cannot find anything that helps me solve this.

26th Oct 2021, 12:53 AM
Kianna Hendricks
Kianna Hendricks - avatar
3 Réponses
+ 4
Yes @Guillem Padilla is right. Arrays only accept integer numbers as their subscript, so you should define x with "int" type, not "double"
26th Oct 2021, 1:00 AM
Rishi
Rishi - avatar
+ 1
You shouldn’t declare x as a double, but as an Integer
26th Oct 2021, 12:56 AM
Guillem Padilla
Guillem Padilla - avatar
0
you are missing " " at the end of the it goes after the hundred take out the break and out << "space";
13th Feb 2023, 5:53 PM
Eliaz Brown