0

How to solve this otherwise I already did multiple times this way but it’s giving mistake at the lines 19

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

15th Dec 2022, 3:59 PM
Ibrahim Bah
Ibrahim Bah - avatar
11 odpowiedzi
+ 6
We cannot see your code. Hence we cannot check what your tried or why it gives an error on line 7. Please link your code, so we can inspect it and help you to find the issue.
15th Dec 2022, 6:57 PM
Lisa
Lisa - avatar
+ 7
Please do not put code in the tag section – put the relevant programming language there! Please link your code so we can check on it.
15th Dec 2022, 4:30 PM
Lisa
Lisa - avatar
+ 2
According to the task description, you only need one input: put the line with cin before the loop. Check for unmatched {}: the return 0; needs to go inside of the main() method.
15th Dec 2022, 8:18 PM
Lisa
Lisa - avatar
+ 2
Ibrahim Bah I told you.... "using namespace std" cannot be on the same line as #include <iostream>
18th Dec 2022, 12:01 PM
Scott D
Scott D - avatar
+ 1
Ibrahim Amadou Mouctar Bah using namespace std needs to be on line 2, not the same line as #include <iostream> Comments in c++ will not work in c++ with the # symbol. Single line comments: // single line comment Multiple lines: /* this comment is a multiple line comment */ Lisa is right, cin should be before the "for" loop - in this case it doesn't matter but sometimes it does. Only put that in a loop if necessary. Also as she said, check for unmatched { } as the "for" loop is not properly guarded and the int main function/method is not properly closed. It's also good to indent for loops to make the code cleaner and to seperate them visually from the variables before.
16th Dec 2022, 4:41 AM
Scott D
Scott D - avatar
0
#include <iostream> using namespace std; /*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*/ int main(){ double items[] = {500, 12.4, 94, 45, 3, 81, 1000.9, 85, 90, 1, 35}; int p; for (int x = 0; x < 11; x++) { cin >>p; cout << items[x]- items [x]*p/100 << " "; } return 0; } tweaked it a little and works
16th Dec 2022, 10:45 PM
superyo
0
Ibrahim Amadou Mouctar Bah What Lisa and I suggested does in fact work. And it's customary to offer hints and tips, not to hand you fully formed solutions, you don't learn by having someone else solve the exercises for you.
17th Dec 2022, 5:32 AM
Scott D
Scott D - avatar
- 1
I kow just i wanted to do it there once to get a quick answer
15th Dec 2022, 5:31 PM
Ibrahim Bah
Ibrahim Bah - avatar
15th Dec 2022, 7:47 PM
Ibrahim Bah
Ibrahim Bah - avatar
- 1
Like i said i only wanted a quick answer but you are not able to help just still trying to be the Elonmusk from sololearn or what and what’s Lisa said it didn’t work also i used this and didn’t work anyway
16th Dec 2022, 11:20 AM
Ibrahim Bah
Ibrahim Bah - avatar
- 1
What they telling me is in the << line 19 'cin' was not declared in this scope; did you mean 'std::cin'?>>
17th Dec 2022, 3:12 PM
Ibrahim Bah
Ibrahim Bah - avatar