Mar 20, 2010 at 7:24pm UTC
A simple calculator that's my second code.What now?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
#include <iostream>
#include <string>
using namespace std;
int main()
{
long int number;
long int times;
string ans;
int cat = 0;
do
{
cout<<"multiplication,addition,subtraction or division?" <<"\n" ;
cin>> ans;
{
if (ans == "multiplication" ||ans == "multi" ||ans == "m" )
{
cat=1;
cout<<"Please enter a number: " ;
cin>>number;
cin.ignore();
cout<<"Multiply by:" ;
cin>>times;
cin.ignore();
cout<<number<<"x" <<times<<"=" <<number*times<<"\n" ;
cout<<"Kazam's calculator." ;
cin.get();
cat=0;
}
if (ans == "addition" ||ans == "add" ||ans == "a" )
{
cat=1;
cout<<"Please enter a number: " ;
cin>>number;
cin.ignore();
cout<<"Add:" ;
cin>>times;
cin.ignore();
cout<<number<<"+" <<times<<"=" <<number+times<<"\n" ;
cout<<"Kazam's calculator." ;
cin.get();
cat=0;
}
if (ans == "subtraction" ||ans == "sub" ||ans == "s" )
{
cat=1;
cout<<"Please enter a number: " ;
cin>>number;
cin.ignore();
cout<<"Subtract:" ;
cin>>times;
cin.ignore();
cout<<number<<"-" <<times<<"=" <<number-times<<"\n" ;
cout<<"Kazam's calculator." ;
cin.get();
cat=0;
}
if (ans == "division" ||ans == "div" ||ans == "d" )
{
cat=1;
cout<<"Please enter a number: " ;
cin>>number;
cin.ignore();
cout<<"Divide by:" ;
cin>>times;
cin.ignore();
if (times <=0)
{
cout<<"Can't divide by zero or less than zero." <<"\n" ;
}
else
{
cout<<number<<"/" <<times<<"=" <<number/times<<"\n" ;
cout<<"Kazam's calculator." ;
cin.get();
}
cat=0;
}
}
}
while (cat == 0);
}
Last edited on Mar 20, 2010 at 8:26pm UTC
Mar 20, 2010 at 8:02pm UTC
you can't divide a number by zero on the windows calculator either.
thanks for the links.
Mar 20, 2010 at 9:41pm UTC
Why can't I divide by less than zero? :(. My windows calculator says 'cannot divide by zero' when I try...a reasonable message.
Last edited on Mar 20, 2010 at 9:45pm UTC