Created
May 4, 2016 23:01
-
-
Save batmantec/b1c63762554deacd06ded4ec3a5f9796 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <string> | |
#include <cstdlib> | |
#include <ctime> | |
#include <cmath> | |
using namespace std; | |
// Functions from other programs | |
int sum(int a, int b){ | |
int c; | |
c=a+b; | |
return c; | |
} | |
int dif (int a, int b){ | |
int e; | |
e=a-b; | |
return e; | |
} | |
int product (int a, int b){ | |
int f; | |
f=a*b; | |
return f; | |
} | |
int divider (int a, int b){ | |
int g; | |
g=a/b; | |
return g; | |
} | |
int rem (int a, int b){ | |
int h; | |
h=a%b; | |
return h; | |
} | |
//End of functions of other programs | |
int simpleCalculator (int num1, int num2){ | |
cout << " The sum of the two numbers is: "<< num1+num2 <<endl; | |
cout << " The diference of the two numbers is: "<< num1-num2 <<endl; | |
cout << " The product of the two numbers is: "<< num1*num2 <<endl; | |
cout << " The integer based division of the two numbers is: "<< num1/num2 <<endl; | |
cout << " The remainder of the two numbers is: "<< num1%num2 <<endl; | |
} | |
int tempConverter (int datain){ | |
int dataout; | |
cout << " The temperature of "<< datain; | |
dataout= 5*(datain-32)/9; | |
cout << " and the temperature in Celsius is "<< dataout <<endl; | |
if (dataout>=100) | |
cout << " Water does boil at this temperature."<<endl; | |
else | |
cout << " Water does not boil at this temperature."<<endl; | |
} | |
int integerSum (int low, int up){ | |
int sum=1, olow; | |
olow=low; | |
if (low<=up){ | |
do { | |
low++; | |
sum=sum+low; | |
} while(low!=up); | |
cout<<" The sum of "<<olow<<" and "<<up<<" numbers is "<<sum<<endl;} | |
else{ | |
cout<<" The number that you typed was upper than the upper number"; | |
} | |
return 0; | |
} | |
int functionCalc(int a, int b) | |
{ | |
int d,e,f,g,h; | |
d=sum (a,b); | |
e=dif(a,b); | |
f=product (a,b); | |
g=divider(a,b); | |
h=rem(a,b); | |
cout << endl <<" The sum of the numbers is: "<<d<<endl; | |
cout << endl <<" The rest of the numbers is: "<<e<<endl; | |
cout << endl <<" The multiplication of the two numbers is: "<<f<<endl; | |
cout << endl <<" The division of the two numbers is: "<<g<<endl; | |
cout << endl <<" The remainder of the division is: "<<h<<endl; | |
return 0; | |
} | |
int main (){ | |
int menu; | |
cout << endl << "Hey there, this program is a compilation of all course programs!" << endl << endl; | |
cout << "################################################################" << endl << endl; | |
cout << "############################# MENU #############################" << endl << endl; | |
cout << "################################################################" << endl << endl; | |
cout << "-------- TYPE THE NUMBER OF THE PROGRAM YOU WANT TO USE --------" << endl << endl; | |
cout << " 1. Simple Calculator (sum, rest, mult, divides and remaninder)" << endl; | |
cout << " 2. Temperature Converter (converts F° to C°)" << endl; | |
cout << " 3. Lucky Game" << endl; | |
cout << " 4. Integer Sum" << endl; | |
cout << " 5. Function Calculator" << endl; | |
cout << " 6. Factorial Calculator" << endl; | |
cout << endl << " Please select an option: "; | |
cin >> menu; | |
cout << endl; | |
switch (menu) { | |
case 1: | |
int num1, num2; | |
cout << " Please enter a integer number: "; | |
cin >> num1; | |
cout << " Please enter a second integer number: "; | |
cin >> num2; | |
simpleCalculator(num1, num2); | |
break; | |
case 2: | |
int datain; | |
cout << " Enter the temperature in Fahrenheit: "; | |
cin >> datain; | |
tempConverter(datain); | |
break; | |
case 3: | |
int user; | |
cout << " You have to guess the number between 1 and 100 "<<endl; | |
cin >> user; | |
int random, counter; | |
srand(time(0)); | |
random = rand()%101; | |
for(counter=1; user!=random; counter++){ | |
if(user!=random){ | |
if(user>random) | |
cout<<" The number is to high, please try again."<<endl; | |
if(user<random) | |
cout<<" The number is to low, please try again."<<endl; | |
cin>>user; | |
} | |
} | |
if(user==random){ | |
cout<<" ###########################"<<endl; | |
cout<<" #You get the right number!#"<<endl; | |
cout<<" # You made it at "<<counter<<" time. #"<<endl; | |
cout<<" ###########################"<<endl; | |
} | |
break; | |
case 4: | |
int up, low; | |
cout<<" This program calculates the sum of 2 integer numbers that you give"<<endl; | |
cout<<" Please, give me lower number: "; | |
cin>>low; | |
cout<<" Please give me upper number: "; | |
cin>>up; | |
integerSum(low, up); | |
break; | |
case 5: | |
int a, b; | |
cout<<" Give me the first integer number: "; | |
cin>>a; | |
cout << endl <<" Give me the second integer number: "; | |
cin>>b; | |
functionCalc(a, b); | |
break; | |
case 6: | |
long long int n,count,product,sum,fac; | |
char answ; | |
cout<<" This program calculate the factorial of a number."<<endl; | |
do { | |
cout << endl << " Please type an positive number: "; | |
cin >> n; | |
count=1; | |
product=1; | |
sum=1; | |
if (n>1) { | |
do{ | |
count++; | |
product=product*(sum+1); | |
sum++; | |
fac=product; | |
}while (count!=n); | |
cout <<" The factorial of "<<n<<" is: "<<fac<<endl << endl; | |
cout <<" Would you like to type another number (y/n)? "; | |
cin >> answ; | |
} else { | |
if (n==1) { | |
cout << endl <<" The factorial of 1 is: 1"<<endl; | |
cout << endl << " Would you like to type another number (y/n)? "; | |
cin>>answ; | |
} else { | |
cout<<" The number that you enter was negative, please try again."<<endl; | |
answ='y'; | |
} | |
} | |
} while(answ=='y'); | |
break; | |
default: | |
cout << endl << " Please select a valid option." << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment