........

......
Last edited on
Credits to @lastchance for this: see
http://www.cplusplus.com/forum/general/212058/#msg992078

1
2
3
4
5
6
7
8
9
10
11
constexpr char symbol[36] = {
  '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F',
  'G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V',
  'W','X','Y','Z'
};

std::string to_base(int n, int base)
{ return n > 0 ? to_base( n / base, base ) + symbol[n % base] : ""; }

std::string to_quarternary(int n) { return to_base(n, 4); }
std::string to_octal(int n) { return to_base(n, 8); } 
Last edited on
.....
Last edited on
its a requirement we use the functions I have above

Do you mean merely printQuarternary and printOctal? Or are there other requirements? For example, do you have to implement these functions in a certain way?

As it stands, just do this:
1
2
void printQuaternary(int n, std::ostream& s) { s << to_quarternary(n) << '\n'; }
void printOctal(int n, std::ostream& s) { s << to_octal(n) << '\n'; }


If there are other requirements, what are they?
Last edited on
@macXnXcheese117

Please DON'T delete your posts after you've got your answer. It renders the thread useless for others to learn from. It's a selfish abuse of this forum.
Topic archived. No new replies allowed.