M
MZaza
That's a calculator and there is an option which should convert the
result you got to binary, but when I try to do so I get a Windows
error stating that the applications has encountered an error..
#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int c, b, i;
double x, y;
double r;
char o;
cout <<"Enter the mathmatical operation, for example 1+2:" <<endl;
cin >>x >>o >>y;
switch (o)
{
case '+': r=x+y;
cout <<"The result is: " <<r <<endl;
break;
case '-': r=x-y;
cout <<"The result is: " <<r <<endl;
break;
case '*': r=x*y;
cout <<"The result is: " <<r <<endl;
break;
case '/': r=x/y;
cout <<"The result is: " <<r <<endl;
break;
case '^': r=pow(x, y);
cout <<"The result is: " <<r <<endl;
break;
default: cout <<"Error: wrong input" <<endl;
}
while (true)
{
cout <<endl <<"-Press 1 to use the result in another
mathmatical operation" <<endl <<"-Press 2 to clear the following
result and continue using the calculator" <<endl <<"-Press 3 to go to
the extra menu" <<endl <<"-Press 4 to exit" <<endl;
cin >>c;
if (c==1)
{
cout <<"Enter the mathamtical operation, for
example +1:" <<endl;
cin >>o >>y;
switch (o)
{
case '+': x=r+y;
cout <<"The result is: " <<x <<endl;
r=x;
break;
case '-': x=r-y;
cout <<"The result is: " <<x <<endl;
r=x;
break;
case '*': x=r*y;
cout <<"The result is: " <<x <<endl;
r=x;
break;
case '/': x=r/y;
cout <<"The result is: " <<x <<endl;
r=x;
break;
case '^': x=pow(r, y);
cout <<"The result is: " <<x <<endl;
r=x;
break;
default: cout <<"Error: wrong input" <<endl;
}
}
else if (c==2)
{
r==0;
cout <<"Enter the mathmatical operation, for example
1+2:" <<endl;
cin >>x >>o >>y;
switch (o)
{
case '+': r=x+y;
cout <<"The result is: " <<r <<endl;
break;
case '-': r=x-y;
cout <<"The result is: " <<r <<endl;
break;
case '*': r=x*y;
cout <<"The result is: " <<r <<endl;
break;
case '/': r=x/y;
cout <<"The result is: " <<r <<endl;
break;
case '^': r=pow(x, y);
cout <<"The result is: " <<r <<endl;
break;
default: cout <<"Error: wrong input" <<endl;
}
}
else if (c==3)
{
cout <<endl <<"-Press 1 to convert the result to
binary" <<endl <<"-Press 2 to convert the result to octal" <<endl <<"-
Press 3 to convert the result to hexa" <<endl <<"-Press 4 to go back"
<<endl;
cin >>c;
if (c==1)
{
b==r;
int m[100];
while (b!=0)
{
m=b%2;
i++;
b=b/2;
}
for (int v=i; v>=0; v--)
cout << m[v];
}
else if (c==2)
{
b==r;
int m[50];
while (b!=0)
{
m=b%8;
i++;
b=b/2;
}
for (int v=i; v>=0; v--)
cout << m[v];
}
else if (c==3)
{
b==r;
int m[50];
while (b!=0)
{
m=b%16;
i++;
b=b/2;
}
for (int v=i; v>=0; v--)
cout << m[v];
}
else if (c==4)
{
}
}
else if (c==4)
std::exit(EXIT_FAILURE);
}
system("PAUSE");
return EXIT_SUCCESS;
}
result you got to binary, but when I try to do so I get a Windows
error stating that the applications has encountered an error..
#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int c, b, i;
double x, y;
double r;
char o;
cout <<"Enter the mathmatical operation, for example 1+2:" <<endl;
cin >>x >>o >>y;
switch (o)
{
case '+': r=x+y;
cout <<"The result is: " <<r <<endl;
break;
case '-': r=x-y;
cout <<"The result is: " <<r <<endl;
break;
case '*': r=x*y;
cout <<"The result is: " <<r <<endl;
break;
case '/': r=x/y;
cout <<"The result is: " <<r <<endl;
break;
case '^': r=pow(x, y);
cout <<"The result is: " <<r <<endl;
break;
default: cout <<"Error: wrong input" <<endl;
}
while (true)
{
cout <<endl <<"-Press 1 to use the result in another
mathmatical operation" <<endl <<"-Press 2 to clear the following
result and continue using the calculator" <<endl <<"-Press 3 to go to
the extra menu" <<endl <<"-Press 4 to exit" <<endl;
cin >>c;
if (c==1)
{
cout <<"Enter the mathamtical operation, for
example +1:" <<endl;
cin >>o >>y;
switch (o)
{
case '+': x=r+y;
cout <<"The result is: " <<x <<endl;
r=x;
break;
case '-': x=r-y;
cout <<"The result is: " <<x <<endl;
r=x;
break;
case '*': x=r*y;
cout <<"The result is: " <<x <<endl;
r=x;
break;
case '/': x=r/y;
cout <<"The result is: " <<x <<endl;
r=x;
break;
case '^': x=pow(r, y);
cout <<"The result is: " <<x <<endl;
r=x;
break;
default: cout <<"Error: wrong input" <<endl;
}
}
else if (c==2)
{
r==0;
cout <<"Enter the mathmatical operation, for example
1+2:" <<endl;
cin >>x >>o >>y;
switch (o)
{
case '+': r=x+y;
cout <<"The result is: " <<r <<endl;
break;
case '-': r=x-y;
cout <<"The result is: " <<r <<endl;
break;
case '*': r=x*y;
cout <<"The result is: " <<r <<endl;
break;
case '/': r=x/y;
cout <<"The result is: " <<r <<endl;
break;
case '^': r=pow(x, y);
cout <<"The result is: " <<r <<endl;
break;
default: cout <<"Error: wrong input" <<endl;
}
}
else if (c==3)
{
cout <<endl <<"-Press 1 to convert the result to
binary" <<endl <<"-Press 2 to convert the result to octal" <<endl <<"-
Press 3 to convert the result to hexa" <<endl <<"-Press 4 to go back"
<<endl;
cin >>c;
if (c==1)
{
b==r;
int m[100];
while (b!=0)
{
m=b%2;
i++;
b=b/2;
}
for (int v=i; v>=0; v--)
cout << m[v];
}
else if (c==2)
{
b==r;
int m[50];
while (b!=0)
{
m=b%8;
i++;
b=b/2;
}
for (int v=i; v>=0; v--)
cout << m[v];
}
else if (c==3)
{
b==r;
int m[50];
while (b!=0)
{
m=b%16;
i++;
b=b/2;
}
for (int v=i; v>=0; v--)
cout << m[v];
}
else if (c==4)
{
}
}
else if (c==4)
std::exit(EXIT_FAILURE);
}
system("PAUSE");
return EXIT_SUCCESS;
}