A 5 Function Calculator
Just a simple calculator that will add, subtract, multiply, divide, and it will also do powers like 5^3 = 125.
AI
AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Source Code
#include <iostream.h>
#include <conio.h>
float inputOne, inputTwo, answer;
char operator_, yn;
int main()
{
textcolor(LIGHTGREEN);
while (yn != 'n')
{
clrscr();
cout << "First number + - / * ^ second number\n";
cin >> inputOne >> operator_ >> inputTwo;
if (operator_ == '+')
answer = inputOne + inputTwo;
if (operator_ == '-')
answer = inputOne - inputTwo;
if (operator_ == '*')
answer = inputOne * inputTwo;
if (operator_ == '/')
{
if (inputTwo == 0)
{
cout << "Cannot divide by 0";
}
else
answer = inputOne / inputTwo;
}
if (operator_ == '^')
{
answer = inputOne;
for (int i=2; i<=inputTwo; i++)
answer = answer * inputOne;
}
cout << endl;
cout << inputOne << " " << operator_ << " ";
cout << inputTwo << " = " << answer;
cout << "\n\nSolve another? <yn> ";
cin >> yn;
cout << "\n";
}
return 0;
}
<p><b>Free Threading</b></p>
<p>For the first time, VB.NET has given VB developers the ability to write truly
freethreaded<br>
applications. If your application is going to perform a task that could take
a<br>
long time, such as parsing through a large recordset or performing a complex
series<br>
of mathematical calculations, you can push that processing off to its own thread
so<br>
that the rest of your application is still accessible. In VB6, the best you
could do to<br>
keep the rest of the application from appearing to be locked was to use the
DoEvents<br>
method.</p>
<p>Examine this code, which is written for VB.NET. Here you have some code for<br>
button1. This code calls the BeBusy routine, which has a loop in it to just
to take up<br>
time. However, while in this loop, you are consuming the thread for this application,<br>
and the UI will not respond while the loop is running. </p>
<p>Open a new VB project. Add a button.</p>
<p><font color="#3366FF">Private Sub</font> button1_Click(<font color="#3366FF">ByVal</font>
sender <font color="#3366FF">As</font> System.Object, _<br>
<font color="#3366FF">ByVal</font> e <font color="#3366FF">As</font>
System.EventArgs) <font color="#3366FF">Handles</font> button1.Click<br>
BeBusy()<br>
End Sub<br>
<br>
<font color="#3366FF">Sub</font> BeBusy()<br>
<font color="#3366FF">Dim</font> i <font color="#3366FF">As Decimal</font><br>
<font color="#3366FF">For</font> i = 1 <font color="#3366FF">To</font>
20000000<br>
<font color="#009933">‘do nothing but
tie up app</font><br>
<font color="#3366FF">Next</font><br>
Beep()<br>
End Sub </p>
<p>To create a thread, you must use the System.Threading.Thread class.</p>
<p><font color="#3366FF">Imports</font> System.Threading.Thread<br>
</p>
<p>To fix the code and keep BeBusy from consuming the main program thread, you
have<br>
now created a new thread and will run BeBusy on that thread. However, that line
of<br>
code isn’t enough. Next, you must call the Start method on that new thread.
With<br>
VB.NET, calling BeBusy on its own thread would look like this:<br>
<br>
<font color="#3366FF">Private Sub</font> button1_Click(<font color="#3366FF">ByVal</font>
sender <font color="#3366FF">As</font> System.Object, _<br>
<font color="#3366FF">ByVal</font> e <font color="#3366FF">As</font>
System.EventArgs) Handles button1.Click<br>
<br>
<font color="#FFFFFF">'<font color="#009933">Creatre a new thread</font></font><br>
<font color="#3366FF">Dim</font> busyThread <font color="#3366FF">As
New </font>System.Threading.Thread(<font color="#3366FF">AddressOf</font> BeBusy)<br>
busyThread.Start()<br>
End Sub </p>
Original Comments (3)
Recovered from Wayback Machine