# A Mini Calculator

Page 1 of 1

## 5 Replies - 5248 Views - Last Post: 16 October 2012 - 09:37 AM

### #1 quim

Reputation: 18
• Posts: 182
• Joined: 11-December 05

# A Mini Calculator

Posted 29 December 2005 - 07:09 AM

Description: when you are asked to to input you calculation input
some thing in this format (ex: 3+4)-> a number followed by a sign and then enter another number and press enter.with this mini calculator you can multiply, devide
```#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
int main ()
{
//declare variable
char expr;

double number1,
number2,
total;

//output to the user
cout << "This is a mini calculator.This calculator:n"
<< "Add +nSubtract -nMultiply *nDivide /nPower ^n"

while (true)
{
cin >>number1 >> expr >> number2;
switch (expr)
{
case '+':
total = number1 + number2;
cout << number1 <<" + " << number2 << " = " << total <<endl;
break;

case '*':
total = number1 * number2;
cout << number1 <<" * " << number2 << " = " << total <<endl;
break;

case '/':
total = number1 / number2;
cout << number1 <<" / " << number2 << " = " << total <<endl;
break;

case '-':
total = number1 - number2;
cout << number1 <<" - " << number2 << " = " << total <<endl;
break;

case '^':
cout << number1 <<" ^ " << number2 << " = " << pow (number1, number2) <<endl;
break;

default:
cout << "This is an invalid input" <<endl;

}
}
system ("PAUSE");
return 0;
}
```

Is This A Good Question/Topic? 0

## Replies To: A Mini Calculator

### #2 Lovee

Reputation: 0
• Posts: 1
• Joined: 10-February 08

## Re: A Mini Calculator

Posted 20 February 2008 - 02:24 AM

very well done

### #3 TheMagnitude

Reputation: 4
• Posts: 144
• Joined: 12-January 08

## Re: A Mini Calculator

Posted 11 March 2008 - 07:50 AM

This isnt a snippet...

### #4 santu47

Reputation: 0
• Posts: 0
• Joined: 20-June 11

## Re: A Mini Calculator

Posted 20 June 2011 - 06:56 AM

still requires some changes for better execution

### #5 Blaylok

Reputation: -2
• Posts: 7
• Joined: 19-August 12

## Re: A Mini Calculator

Posted 27 September 2012 - 07:50 AM

ERRORS... Line 4: > using namespace std;.. is not needed. line 20: while(true) > true is not defined anywhere... correction: dont write the while statement... It is not needed at all...

### #6 quim

Reputation: 18
• Posts: 182
• Joined: 11-December 05

## Re: A Mini Calculator

Posted 16 October 2012 - 09:37 AM

this snippet is so only i was still in high school and i was just beginning to learn c++ at that time. correction from the last comment: yes using namespace std; is needed otherwise i will have to prefix the std::cout, std::cin and other objects that are part of the standard library. also while true is required if you want to keep prompting the user for more calculation. you must use some kind of loop statement to keep prompting the user to enter calculation.