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 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.
+ 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?