Could i done it simplier? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Could i done it simplier?

Array problem "What s my discount": Solved it like this: #include <iostream> using namespace std; int main() { double items[] = {500, 12.4, 94, 45, 3, 81, 1000.9, 85, 90, 1, 35}; //your code goes here int discount; cin >> discount; for ( int x = 0; x < 11 ; x++ ){ items[x] = items[x] - items[x] * discount / 100; cout << items[x] << " "; } return 0; } Was there a way to write the: (items[x] = items[x] - items[x] * discount / 100; ) simplier?

6th Jul 2021, 7:39 AM
Mandoc Mihai
Mandoc Mihai - avatar
4 Answers
+ 2
item[x] -= item[x] * discount / 100;
6th Jul 2021, 7:45 AM
visph
visph - avatar
+ 2
You can go ahead and leave it as someone else may run into the same issue :)
6th Jul 2021, 8:29 AM
Simba
Simba - avatar
+ 1
or even: item[x] *= 1 - discount / 100;
6th Jul 2021, 7:46 AM
visph
visph - avatar
0
Interesting way of doing it, thx guys, should i delete the post after i get it solved?
6th Jul 2021, 7:48 AM
Mandoc Mihai
Mandoc Mihai - avatar