Converting ascii substr to int
<p>first year college having problem converting ascii into int.</p>

<p>The problem is this piece of code</p>

<p>unsigned short iminutes = ((minutes[3]-48)*10) + (minutes[4]-48);</p>

<p>When I run this on codeblocks at home it returns an incorrect value, when I run it again I get a different incorrect value.</p>

<p>When I run it at on Borlands at college, the screen just ups and disappears before I can read it, so I can't use the system clock here either. </p>

<p>It's Easter hols now so even though I'm at college, I can't annoy my tutors because they're not.</p>

<pre><code>#include &lt;iostream.h&gt;
#include &lt;conio.h&gt;
#include &lt;string&gt;
//#include &lt;time.h&gt;
//#include &lt;ctype.h&gt;


using namespace std;

int main() {

bool q = false;


do {

// convert hours to minutes ... then total all the minutes
// multiply total minutes by $25.00/hr
// format (hh:mm:ss)


string theTime;

cout &lt;&lt; "\t\tPlease enter time  " &lt;&lt; endl;
cout &lt;&lt;"\t\t";
cin &gt;&gt; theTime;
cout &lt;&lt; "\t\t"&lt;&lt; theTime &lt;&lt; "\n\n";

string hours = theTime.substr (0, 2);
cout &lt;&lt;"\t\t"&lt;&lt; hours &lt;&lt; endl;
unsigned short ihours = (((hours[0]-48)*10 + (hours[1] -48))*60);
cout &lt;&lt; "\t\t"&lt;&lt; ihours &lt;&lt; endl;

string minutes = theTime.substr (3, 2);
cout &lt;&lt;"\t\t"&lt;&lt; minutes &lt;&lt; endl;
unsigned short iminutes = ((minutes[3]-48)*10) + (minutes[4]-48);
cout &lt;&lt; "\t\t" &lt;&lt; iminutes &lt;&lt; endl;

cout &lt;&lt; "\n\n\t\tTotal Minutes  " &lt;&lt;(ihours + iminutes);
cout &lt;&lt; "\n\n\t\tTotal Value  " &lt;&lt;(ihours + iminutes)*(25.00/60) &lt;&lt; "\n\n";

}

while (!q);

cout &lt;&lt; "\t\tPress any key to continue ...";
getch();
return 0;
}
</code></pre>
