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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$         
$                                               $
$                                               $
$                        $                      $
$                       $$$                     $
$                      $ $                      $
$                      $ $                      $
$                       $$$                     $
$                        $ $                    $
$                        $ $                    $
$                       $$$                     $
$                        $                      $
$                                               $
$                                               $
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <string>
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
Registered users can post here. Sign in or register to post.