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
11 ответов
+ 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.
+ 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.
+ 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.
+ 2
Ibrahim Bah
I told you....
"using namespace std" cannot be on the same line as #include <iostream>
+ 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.
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
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.
- 1
I kow just i wanted to do it there once to get a quick answer
- 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
- 1
What they telling me is in the << line 19 'cin' was not declared in this scope; did you mean 'std::cin'?>>