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

#1 quim   User is offline

  • D.I.C Head
  • member icon

Reputation: 18
  • View blog
  • 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
add, subtract, and do exponent...
#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"
           << "nInput your calculation"<<endl;
     
     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   User is offline

  • New D.I.C Head

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

Re: A Mini Calculator

Posted 20 February 2008 - 02:24 AM

very well done
Was This Post Helpful? 0
  • +
  • -

#3 TheMagnitude   User is offline

  • D.I.C Head
  • member icon

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

Re: A Mini Calculator

Posted 11 March 2008 - 07:50 AM

This isnt a snippet...
Was This Post Helpful? 0
  • +
  • -

#4 santu47   User is offline

  • New D.I.C Head

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

Re: A Mini Calculator

Posted 20 June 2011 - 06:56 AM

still requires some changes for better execution
Was This Post Helpful? 0
  • +
  • -

#5 Blaylok   User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • 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...
Was This Post Helpful? 0
  • +
  • -

#6 quim   User is offline

  • D.I.C Head
  • member icon

Reputation: 18
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1