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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
// Calculator Section
float num1;
float num2;
float addition(float num1, float num2){
float equals1;
equals1 = num1 + num2;
return (equals1);
}
float subtraction(float num1, float num2){
float equals1;
equals1 = num1 - num2;
return (equals1);
}
float multiplication(float num1, float num2){
float equals1;
equals1 = num1 * num2;
return (equals1);
}
float division(float num1, float num2){
float equals1;
equals1 = num1 / num2;
return (equals1);
}
float power(float num1, float num2){
float equals1;
equals1 = pow(num1, num2);
return (equals1);
}
float square(float num1){
float equals1;
equals1 = sqrt(num1);
return (equals1);
}
void calculator(void)
{
char again1;
do{
char mathfunc1;
//Gather problem
system("CLS");
cout << "Enter the first number in the problem." << endl;
cin >> num1;
system("CLS");
cout << "Enter the mathematical function you want to use (+,-,*,/,^,#)." << endl;
cin >> mathfunc1;
system("CLS");
if(mathfunc1 != '#'){
cout << "Enter the second number in the problem." << endl;
cin >> num2;
system("CLS");
}
// Answer Problem
switch(mathfunc1)
{
case '+':
cout << "The answer to your math problem is: " << addition(num1, num2) << endl;
break;
case '-':
cout << "The answer to your math problem is: " << subtraction(num1, num2) << endl;
break;
case '*':
cout << "The answer to your math problem is: " << multiplication(num1, num2) << endl;
break;
case '/':
cout << "The answer to your math problem is: " << division(num1, num2) << endl;
break;
case '^':
cout << "The answer to your math problem is: " << power(num1, num2) << endl;
break;
case '#':
cout << "The answer to your math problem is: " << square(num1) << endl;
break;
default:
cout << "The information you input was invalid." << endl;
break;
}
cout << "Do you want to do another math problem?" << endl;
cin >> again1;
}while(again1 == 'y' || again1 == 'Y');
}
// End Calculator
// Test Section
void test(void)
{
int amountquestions1 = 0;
char amountquestions2;
do{
cout << "How many questions do you want in your test, maximum of 25?" << endl;
cin >> amountquestions1;
cout << "Are you sure you want " << amountquestions1 << "?" << endl;
cin >> amountquestions2;
}while(amountquestions2 != 'y' || amountquestions2 != 'Y' );
}
// End Test Section
int main(int argc, char *argv[])
{
system("TITLE Calculator");
system("COLOR f2");
string testvcalc1;
cout << "Do you want to use the calculator or make a test?" << endl;
cin >> testvcalc1;
if(testvcalc1 = 'calculator'){
cout << calculator;
}
else if(testvcalc1 = 'test'){
cout << test;
}
cin.ignore();
return EXIT_SUCCESS;
}
|