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; }
6 Antworten
+ 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.
+ 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
+ 1
Shadow Yep, just realized that. Thank you so much :)
+ 1
Plaush No worries.. Its fine ... You're welcome ...
0
Michał Doruch Sadly, it didn’t work :(
0
Its working fine for me in playground... whats actually problem.. do you dont need new line after all outputs?