How to create a program with some functions for a calculator. Functions include:
1.) add
2.) subtract
3.) multiply
4.) division
a.) Write the algorithm with pseudo code to provide solution to the problem
statements stated above.
b.) Implement all the calculator functions listed above with C++ programming.
Sample Output:
Enter the calculation u want to perform:1*2+15/5-10
The answer is :-7
Do u want to continue(Y/N):y
Enter the calculation u want to perform:
C++ programming?
This is not exactly what you are looking for, but I did make a program of my own to do something similar. The link is here: http://www.pastebin.ca/1009026 . Sorry about it being so choppy, I have been doing some work with it. Feel free to copy this and use it as a reference if you wish.
Reply:// Program to implement Calculator functions for : +, -, *, /, ^
#include %26lt;iostream.h%26gt;
#include %26lt;conio.h%26gt;
float inputOne, inputTwo, answer;
char operator_, yn;
int main()
{
textcolor(LIGHTBLUE);
while (yn != 'n')
{
clrscr();
cout %26lt;%26lt; "First number + - / * ^ second number\n";
cin %26gt;%26gt; inputOne %26gt;%26gt; operator_ %26gt;%26gt; inputTwo;
if (operator_ == '+')
answer = inputOne + inputTwo;
if (operator_ == '-')
answer = inputOne - inputTwo;
if (operator_ == '*')
answer = inputOne * inputTwo;
if (operator_ == '/')
{
if (inputTwo == 0)
{
cout %26lt;%26lt; "Cannot divide by 0";
}
else
answer = inputOne / inputTwo;
}
if (operator_ == '^')
{
answer = inputOne;
for (int i=2; i%26lt;=inputTwo; i++)
answer = answer * inputOne;
}
cout %26lt;%26lt; endl;
cout %26lt;%26lt; inputOne %26lt;%26lt; " " %26lt;%26lt; operator_ %26lt;%26lt; " ";
cout %26lt;%26lt; inputTwo %26lt;%26lt; " = " %26lt;%26lt; answer;
cout %26lt;%26lt; "\n\nSolve another? %26lt;yn%26gt; ";
cin %26gt;%26gt; yn;
cout %26lt;%26lt; "\n";
}
return 0;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment