• Welcome to ZD Forums! You must create an account and log in to see and participate in the Shoutbox chat on this main index page.

Things That Are on Your Mind

Terminus

If I was a wizard this wouldn't be happening to me
Joined
May 20, 2012
Location
Sub-Orbital Trajectory
Gender
Anarcho-Communist
136 lines of (mostly) perfect code.

#include <iostream>

#include <math.h>

#include <conio.h>
using namespace std;

double add (double x, double y)
{
cout<<"Enter first number:\n";
cin >> x;
cout <<"Enter the second number:\n";
cin>> y;
cin.ignore();
double result = x + y;
cout<<"Result is"<<" "<<result<<endl;
cin.get();
return 0;
}

double subtract (double x, double y)
{ cout<<"Enter first number:\n";
cin >> x;
cout <<"Enter the second number:\n";
cin>> y;
cin.ignore();
double result = x - y;
cout<<"Result is"<<" "<<result<<endl;
cin.get();
return 0;
}

double multiply (double x, double y)
{ cout<<"Enter first number:\n";
cin >> x;
cout <<"Enter the second number:\n";
cin>> y;
cin.ignore();
double result = x*y;
cout<<"Result is"<<" "<<result<<endl;
cin.get();
return 0;
}

double divide (double x, double y)
{ cout<<"Enter first number:\n";
cin >> x;
cout <<"Enter the second number:\n";
cin>> y;
cin.ignore();
double result = x / y;
cout<<"Result is"<<" "<<result<<endl;
cin.get();
return 0;
}

double log (double x, double y)
{ cout<<"Enter the number:\n";
cin >> x;
cout <<"Enter the base:\n";
cin>> y;
cin.ignore();
double result = (log10 (x))/(log10 (y));
cout<<"Result is"<<" "<<result<<endl;
cin.get();
return 0;
}

double exponent (double x, double y)
{cout<<"Enter the Base:\n";
cin >> x;
cout <<"Enter the Exponent:\n";
cin>> y;
cin.ignore();
double result = pow(x,y);
cout<<"Result is"<<" "<<result<<endl;
cin.get();
return 0;
}

double input(double option,double x,double y)
{
while(1)
{
cout<<endl;
cout<<"-----------------------------------------------------\n"<<endl;
cout<<"Please select the option you want to perform"<<endl;
cout<<"1. Addition"<<endl<<"2. Subtraction"<<endl<<"3. Multiplication\n"<<endl
<<"4. Division\n"<<endl<<"5. Logarithm\n"<<endl<<"6. Exponent\n"<<endl<<"7. Exit Calculator\n";
cout<<"\nPlease enter your option:";
cin >>option;
switch(option){
case 1:
cout<<"You have selected Addition\n";
add(x,y);
break;
case 2:
cout<<"You have selected Subtraction\n";
subtract(x,y);
break;
case 3:
cout<<"You have selected Multiplication\n";
multiply(x,y);
break;
case 4:
cout<<"You have selected Division\n";
divide(x,y);
break;
case 5:
cout<<"You have selected Logarithms\n";
divide(x,y);
break;
case 6:
cout<<"You have selected Exponential Functions\n";
divide(x,y);
break;
case 7:
cout<<"Exiting...";
break;
default:
cout<<"Please select a valid option";
}
if (option == 7)
{
break;
}
}
}
int main()
{
cout<<"Caculator";
int option,a,b;
input(option,a,b);
getch();
return 0;
}

1 compilation error that I can't seem to fix...
 
Joined
Feb 23, 2011
136 lines of (mostly) perfect code.

#include <iostream>

#include <math.h>

#include <conio.h>
using namespace std;

double add (double x, double y)
{
cout<<"Enter first number:\n";
cin >> x;
cout <<"Enter the second number:\n";
cin>> y;
cin.ignore();
double result = x + y;
cout<<"Result is"<<" "<<result<<endl;
cin.get();
return 0;
}

double subtract (double x, double y)
{ cout<<"Enter first number:\n";
cin >> x;
cout <<"Enter the second number:\n";
cin>> y;
cin.ignore();
double result = x - y;
cout<<"Result is"<<" "<<result<<endl;
cin.get();
return 0;
}

double multiply (double x, double y)
{ cout<<"Enter first number:\n";
cin >> x;
cout <<"Enter the second number:\n";
cin>> y;
cin.ignore();
double result = x*y;
cout<<"Result is"<<" "<<result<<endl;
cin.get();
return 0;
}

double divide (double x, double y)
{ cout<<"Enter first number:\n";
cin >> x;
cout <<"Enter the second number:\n";
cin>> y;
cin.ignore();
double result = x / y;
cout<<"Result is"<<" "<<result<<endl;
cin.get();
return 0;
}

double log (double x, double y)
{ cout<<"Enter the number:\n";
cin >> x;
cout <<"Enter the base:\n";
cin>> y;
cin.ignore();
double result = (log10 (x))/(log10 (y));
cout<<"Result is"<<" "<<result<<endl;
cin.get();
return 0;
}

double exponent (double x, double y)
{cout<<"Enter the Base:\n";
cin >> x;
cout <<"Enter the Exponent:\n";
cin>> y;
cin.ignore();
double result = pow(x,y);
cout<<"Result is"<<" "<<result<<endl;
cin.get();
return 0;
}

double input(double option,double x,double y)
{
while(1)
{
cout<<endl;
cout<<"-----------------------------------------------------\n"<<endl;
cout<<"Please select the option you want to perform"<<endl;
cout<<"1. Addition"<<endl<<"2. Subtraction"<<endl<<"3. Multiplication\n"<<endl
<<"4. Division\n"<<endl<<"5. Logarithm\n"<<endl<<"6. Exponent\n"<<endl<<"7. Exit Calculator\n";
cout<<"\nPlease enter your option:";
cin >>option;
switch(option){
case 1:
cout<<"You have selected Addition\n";
add(x,y);
break;
case 2:
cout<<"You have selected Subtraction\n";
subtract(x,y);
break;
case 3:
cout<<"You have selected Multiplication\n";
multiply(x,y);
break;
case 4:
cout<<"You have selected Division\n";
divide(x,y);
break;
case 5:
cout<<"You have selected Logarithms\n";
divide(x,y);
break;
case 6:
cout<<"You have selected Exponential Functions\n";
divide(x,y);
break;
case 7:
cout<<"Exiting...";
break;
default:
cout<<"Please select a valid option";
}
if (option == 7)
{
break;
}
}
}
int main()
{
cout<<"Caculator";
int option,a,b;
input(option,a,b);
getch();
return 0;
}

*Calculator...

Correcting that spelling error has been on my mind for quite some time now...
 

CynicalSquid

Swag Master General
Joined
Aug 1, 2012
Location
The End
Gender
Apache Helicopter
Mother's day <3

(I'm not even going to see my mom until 6pm. :P)

I kind of wish Mother's Day was tomorrow though because I could have messed with my fake mother. :P
 

Eduarda

Srishti is annie is eduarda right?
Joined
May 28, 2010
Location
Ontario, Canada.
A pigeon family made it's nest on the roof/arch/thingy of our house. Today, we found out that one of the eggs had fallen down the roof, and is now cracked :( The baby pigeon died.
 

Users who are viewing this thread

Top Bottom