Can't solve C++'s What's My Discount practice task. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can't solve C++'s What's My Discount practice task.

I'm having trouble trying to create code to be used in the practice task found in the Arrays in Calculations section of the C++ course. Here's the code. #include <iostream> using namespace std; int main() { double items[] = {500, 12.4, 94, 45, 3, 81, 1000.9, 85, 90, 1, 35}; int discout; //your code goes here cin >> discout; for (int x = 0; x<11; x++) { items[x]; cout << items[x] - items[x]*discout/100 << " "; } return 0; } The output will give me the expected result, followed by an error message. What am I doing wrong?

8th Mar 2021, 12:05 AM
Ryan Fornelius
4 Answers
+ 1
Remove the 'item[x]' in line 12 as I mentioned above. Everything will be fine
9th Mar 2021, 12:39 AM
Simba
Simba - avatar
+ 1
Hey, it worked! Thanks a lot for the help!!
9th Mar 2021, 4:42 AM
Ryan Fornelius
+ 1
#include <iostream> using namespace std; int main() { double items[] = {500, 12.4, 94, 45, 3, 81, 1000.9, 85, 90, 1, 35}; double disc; cin >> disc; double dPrice; //your code goes here for(int x = 0; x<11; x++){ dPrice = items[x]-items[x]*disc/100; // MARKED LINE cout<<dPrice<<" "; } return 0; } //subtract the equations (items[x]*disc/100) from the original array items[x] // i was stuck with this for a minute
5th Feb 2022, 1:10 AM
William Alley
William Alley - avatar
0
thanks for respnding. Here’s the task im asked to do... 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 (" "). Sample Input 25 Sample Output 375 9.3 70.5 33.75 2.25 60.75 750.675 63.75 67.5 0.75 26.25
8th Mar 2021, 11:50 PM
Ryan Fornelius