+ 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?
4 Respostas
+ 1
Remove the 'item[x]' in line 12 as I mentioned above.
Everything will be fine
+ 1
Hey, it worked! Thanks a lot for the help!!
+ 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
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