Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace std;
- double num1;
- double num2;
- double num3;
- string yesorno;
- string yesorno2;
- string operator1;
- void mean();
- void pausewithtext();
- void gotomain();
- int main()
- {
- printf ("\nThis program will let you +, -, * or / numbers\n Please enter the operator you wish to use: ");
- cin >> operator1; cout << endl;
- printf ("Please enter the first number you wish to use: ");
- cin >> num1; cout << endl;
- printf ("Please enter the second number you wish to use: ");
- cin >> num2; cout << endl;
- printf ("Do you want to use a 3rd number? (y/n)");
- cin >> yesorno; cout << endl;
- if ((yesorno == "y") || (yesorno == "Y")) {
- printf("Please enter the third number you wish to use: ");
- cin >> num3;
- /* This is the code for actual calculating (3 numbers) */
- if (operator1 == "+")
- {
- mean();
- //Addition for 3 numbers
- cout << "Answer: " << num1 + num2 + num3 << endl;
- pausewithtext();
- gotomain();
- }
- else if (operator1 == "-")
- {
- //Subtraction for 3 numbers
- cout << "Answer: " << num1 - num2 - num3 << endl;
- pausewithtext();
- gotomain();
- }
- else if (operator1 == "/")
- {
- //Division for 3 numbers
- cout << "Answer: " << num1 / num2 / num3 << endl;
- pausewithtext();
- gotomain();
- }
- else if (operator1 == "*")
- {
- //Multiplication for 3 numbers
- cout << "Answer: " << num1 * num2 * num3 << endl;
- pausewithtext();
- gotomain();
- }
- else
- {
- printf("This happenes when the operator does not == /, +, - or * with 3 numbers");
- pausewithtext();
- gotomain();
- }
- /* End calculating (3 numbers)*/
- }
- else
- {
- /* This is the code for actual calculating (2 numbers) */
- if (operator1 == "+")
- {
- //Addition with 2 numbers
- cout << "Answer :" << num1 + num2 << endl;
- pausewithtext();
- gotomain();
- }
- else if (operator1 == "-")
- {
- //Subtraction with 2 numbers
- cout << "Answer: " << num1 - num2 << endl;
- pausewithtext();
- gotomain();
- }
- else if (operator1 == "/")
- {
- //Division with 2 numbers
- cout << "Answer: " << num1 / num2 << endl;
- pausewithtext();
- gotomain();
- }
- else if (operator1 == "*")
- {
- //Multiplication with 2 numbers
- cout << num1 * num2 << endl;
- gotomain();
- }
- else
- {
- printf("This happens when the operator does not == /, +, - or * with 3 numbers");
- pausewithtext();
- gotomain();
- }
- /* End calculating (2 numbers)*/
- }
- }
- void mean()
- {
- printf ("\nDo you want to use take the mean of your numbers? (y/n)");
- cin >> yesorno; cout << endl;
- if ((yesorno == "y") || (yesorno == "Y"))
- {
- cout << "The answer is: " << (num1 + num2 + num3) / 3 << endl;
- pausewithtext();
- gotomain();
- }
- else
- {
- }
- }
- void pausewithtext()
- {
- cout << "Press any key to continue...";
- getch();
- }
- void gotomain()
- {
- main();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement