0

[Practice 29.2] Compiler keeps outputting a blank space

Hello, I’m struggling to solve this question as the compiler likes to output a blank space after the last element. I’ve tried using ‘if (x <=11’)’ but that didn’t work. Is it a bug or am I just stupid? Thanks, in advance The code: #include <iostream> using namespace std; int main() { double final = 0; double items[] = {500, 12.4, 94, 45, 3, 81, 1000.9, 85, 90, 1, 35}; int discount; cin >> discount; //your code goes here for(int x=0; x <11; x++) { final = items[x] - items[x] * discount/100; cout<<final<<endl; } return 0; }

7th Mar 2021, 12:00 PM
Plaush
Plaush - avatar
6 Respostas
+ 5
You are supposed to print all the values on the same line, separated by a space. However, std::endl inserts a newline character into the output stream, not a space. Change your output to std::cout << final << ' '; and everything should be correct.
7th Mar 2021, 12:09 PM
Shadow
Shadow - avatar
+ 1
Jayakrishna🇼🇳 Oh, I’m retarded. It doesn’t need a new line, it wants them to all be in the same line. Sorry for wasting your time
7th Mar 2021, 12:09 PM
Plaush
Plaush - avatar
+ 1
Shadow Yep, just realized that. Thank you so much :)
7th Mar 2021, 12:10 PM
Plaush
Plaush - avatar
+ 1
Plaush No worries.. Its fine ... You're welcome ...
7th Mar 2021, 12:12 PM
Jayakrishna 🇼🇳
0
MichaƂ Doruch Sadly, it didn’t work :(
7th Mar 2021, 12:05 PM
Plaush
Plaush - avatar
0
Its working fine for me in playground... whats actually problem.. do you dont need new line after all outputs?
7th Mar 2021, 12:07 PM
Jayakrishna 🇼🇳