Note that there are some explanatory texts on larger screens.

plurals
  1. POUnsigned/signed mismatch
    primarykey
    data
    text
    <p>I'm having trouble fixing this warning message. </p> <p>warning C4018: '&lt;' : signed/unsigned mismatch</p> <p>Can anyone help me find out what the problem is? It's located in the bool function at <code>while (i &lt; bin.length())</code> </p> <pre><code>#include&lt;iostream&gt; #include&lt;string&gt; #include&lt;math.h&gt; using namespace std; void intro(); bool isBinary(string); void decToBin(); string getBin(); void binToDec(string); char getChoice(); char getContinue(); int main() { char choice, cont; string bin; intro(); do{ choice = getChoice(); if(choice == 'b' || choice == 'B') { bin = getBin(); bool binIsBinary = isBinary(bin); if(binIsBinary) binToDec(bin); } else { cout&lt;&lt;"Error!!! Your Number is Not Binary."&lt;&lt;endl; cin.clear(); } if(choice == 'd' || choice == 'B') decToBin(); cont = getContinue(); } while(cont == 'y' || cont == 'Y'); } void intro() { cout &lt;&lt; "This program coverts decimal numbers to binary and vice versa."&lt;&lt;endl; } bool isBinary(string bin) { int i=0; bool binIsBinary = true; while (i &lt; bin.length()) { if( bin.at(i) != '1' &amp;&amp; bin.at(i) != '0' ) { binIsBinary = false; } i++; } return binIsBinary; } void decToBin() { int dec; string bin; cout &lt;&lt; endl &lt;&lt; "Please enter a decimal number:"; cin &gt;&gt; dec; bin = ""; while (dec != 0) { if (dec % 2 == 0) bin.insert(0, "0"); else bin.insert(0, "1"); dec = dec / 2; } cout &lt;&lt; "The equivalent binary number is: " &lt;&lt; bin &lt;&lt; endl &lt;&lt; endl; } string getBin() { string bin; cout &lt;&lt; endl &lt;&lt; "Enter a binary number: "; cin &gt;&gt; bin; return bin; } void binToDec(string bin) { double deci; double len; len = bin.length(); deci = 0; for (int i=0; i&lt;len; i++) if (bin.at(i) == '1') deci = deci + pow(2, len-i-1); cout &lt;&lt; "The equivalent decimal number is: " &lt;&lt; deci &lt;&lt; endl &lt;&lt; endl; } char getChoice() { char choice; cout &lt;&lt; endl &lt;&lt; "If you would like to convert a binary to a decimal then enter b."&lt;&lt;endl; cout &lt;&lt; "If you would like to convert a decimal to a binary then enter d. "; cin &gt;&gt; choice; return choice; } char getContinue() { char cont; cout &lt;&lt; "Would you like to convert another number(Y/N)? "; cin &gt;&gt; cont; return cont; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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