### Complicated dollar sign outputer

does the following script work -- I'm working on a school provided computer and I can't test it out.

it's suppose to output this:
 ``123456789101112131415`` ``````\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$ \$ \$ \$ \$ \$ \$ \$ \$ \$\$\$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$\$\$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$ \$\$\$ \$ \$ \$ \$ \$ \$ \$ \$ \$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$``````

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566`` ``````#include #include using namespace std; unsigned char w = 24; string s = "\$"; string n = "\n"; string c = " "; string g (unsigned char& w, string& buff) { unsigned char t = w / 2 - buff.length () / 2; string y = ""; for (unsigned char e = 0; e < t; e++) { y += c; } return s + y + buff + y + s + n; } string a () { string f = ""; for (unsigned char i = 0; i < w; i++) { f += s; } return s + n; } string z () { string innerText = ""; string p = c + s + s + s + c; for (unsigned char o = 0; o < 2; o++) { string j = o ? c : s; string k = o ? s : c; for (unsigned char q = o ? 0 : 4; o ? q < 4 : q >= 0; o ? q++ : q--){ string buff = ""; switch (q){ case 0: buff = c + c + s + c + c; break; case 1: buff = p; break; case 2: case 3: buff = j + c + s + c + k; break; } innerText += g(w, buff); } innerText += o ? g(w, p) : ""; } return innerText; } int main () { string b = a (); cout << n + b + z() + b; return 0; }``````
Last edited on
 Does the following script work

No. The code never terminates; the loop condition on line 38 given by `o ? q < 4 : q >= 0` is always true.
See: http://coliru.stacked-crooked.com/a/be89f1fd58332e02

A good first step to fixing it would be to pick better names.

 I can't test it out

In the future, try one of:
http://coliru.stacked-crooked.com/
http://rextester.com/l/cpp_online_compiler_gcc
http://ideone.com/
http://cpp.sh/
https://wandbox.org/
https://godbolt.org/

My favorite is Coliru; I use Rextester when I want to use the MSVC compiler. Wandbox usually supports lots of compiler versions (including the bleeding-edge ones), and Godbolt allows inspection of assembled code.
Last edited on
thanks, I fixed it with Corliru -- here's the working version: http://coliru.stacked-crooked.com/a/c410e3785cf32cb2

^
Update: made it scale able: http://coliru.stacked-crooked.com/a/455d982cb1d750c1
Last edited on