Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Note: This is simply a comment-with-code and not an actual answer.</p> <pre><code>int main() { string bin=""; decode(bin); } void decode(string bin) { } </code></pre> <p>This causes a new string to be created on entry into "decode" and the contents of "bin" copied to it. Any changes made to decode::bin will be invisible to main when decode ends.</p> <p>You can avoid this - called "pass by value" because you are passing the values of "bin" and not "bin" itself - by using "pass by reference"</p> <pre><code>void decode(string&amp; bin) </code></pre> <p>But in your code, you don't actually appear to need to pass "bin" at all. If you are going to need "bin" in main after decode, you might instead consider returning it:</p> <pre><code>int main() { string bin = decode(); } string decode() { string bin = ""; ... return bin; } </code></pre> <p>But for now, just remove bin from main and make it a local variable in decode.</p> <pre><code>void bintodec(); int main() { bintodec(); return 0; } void bintodec() { std::string bin = ""; cout &lt;&lt; "Enter the binary number: "; cin &gt;&gt; bin; int temp = 128*(bin[0]-48) + 64*(bin[1]-48) + 32*(bin[2]-48) + 16*(bin[3]-48) + 8*(bin[4]-48) + 4*(bin[5]-48) + 2*(bin[6]-48) + (bin[7]-48); int temp_a = temp%10; temp = (temp - temp_a) / 10; int temp_b = temp%10; temp = (temp - temp_b) / 10; char dec[4] = ""; dec[2] = temp_a+48; dec[1] = temp_b+48; dec[0] = temp+48; dec[3] = '\0'; cout &lt;&lt; endl &lt;&lt; bin &lt;&lt; " in decimal is: " &lt;&lt; dec &lt;&lt; endl; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload