Calculators

Good calculator program for anyone
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
//Selctable calculator
/* with fixes labeled below
XVIII
*/
#include<iostream>
using namespace std;
int main()
{
	cout<<"\nCalculator 2.0";
	cout<<"\nThe calculator where you can select the op.";
	cout<<"\nEnter one integer:";
	int Num1=0;
	int Num2=0;
	int Result=0;
	char Result2;
	cin>>Num1;
	USERSELECTION:
	cout<<"\nEnter the operation.";
	cout<<"Enter 'm' to multiply, 'd'to divide, 'a' to add,\n";
	cout<<"'s' to subtract, 'c' to square, & 'q' to cube\n";
	char Userselection= '\0';
	cin>>Userselection;
	{
	if (Userselection=='c')
	{
	    Result=Num1*Num1;
	    goto RESULTDISPLAY;
	}
	
	else if(Userselection=='q')
	{
	    Result=Num1*Num1*Num1;
	    goto RESULTDISPLAY;
	}
	else if (Userselection=='27';)    //continue
	{
	    Result2="Great job, you achived COWNUM";
	}
	else if(Userselection=='m')
	Result=Num1*Num2;

	else if (Userselection=='d')
	Result=Num1/Num2;

	else if (Userselection=='a')
	Result=Num1+Num2;

	else if (Userselection=='s')
	Result=Num1-Num2;

	else
	cout<<"\nYou entered an invalid answer. Try again.";
	goto USERSELECTION;
	
	
	cout<<"\nEnter another integer:";
	cin>>Num2;
	cout<<"\nNum1 is "<<Num1<<".";
	cout<<"\nNum2 is"<<Num2<<".";
	cout<<"\nDo you wish to change these numbers?";
	
	
	
	
	RESULTDISPLAY://Result Display
	cout<<"\nWELCOME TO RESULT DISPLAY";
	cout<<"\n\t Your Result is";
	cout<<Result"\n";
	cout<<"Result2 is "<<Result2"\n";
	cout<<"Goodbye!!!!!";	
	
	
	return 0;
}
Has some errors... fixing
Better use a loop and break instead of goto.

You forgot the goto after line 60.
Line 43: Check whether Num2 is != 0 or you will have a crash in that case.

After line 51 you need {}:
1
2
3
4
5
else
{
	cout<<"\nYou entered an invalid answer. Try again.";
	goto USERSELECTION;
}


Line 23: } is missing.
Last edited on
Ok....I have an updated version.
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
//Selctable calculator
/* with fixes labeled below
XVIII
*/
#include<iostream>
#include<string>
using namespace std;
int main()
{
	cout<<"\nCalculator 2.0";
	cout<<"\nThe calculator where you can select the op.";
	cout<<"\nEnter one integer:";
	int Num1=0;
	int Num2=0;
	int Result=0;
	string Result2;
	cin>>Num1;
	USERSELECTION:
	cout<<"\nEnter the operation.";
	cout<<"Enter 'm' to multiply, 'd'to divide, 'a' to add,\n";
	cout<<"'s' to subtract, 'c' to square, & 'q' to cube\n";
	char Userselection= '\0';
	cin>>Userselection;
	{
	if (Userselection=='c')
	{
	    Result=Num1*Num1;
	    goto RESULTDISPLAY;
	}
	
	else if(Userselection=='q')
	{
	    Result=Num1*Num1*Num1;
	    goto RESULTDISPLAY;
	}
	else if (Userselection=='27')    //continue
	{
	    Result2="Great job, you achived COWNUM";
	}
	else if(Userselection=='m')
	Result=Num1*Num2;

	else if (Userselection=='d')
	Result=Num1/Num2;

	else if (Userselection=='a')
	Result=Num1+Num2;

	else if (Userselection=='s')
	Result=Num1-Num2;

	else
	{
		cout<<"\nYou entered an invalid answer. Try again.";
		goto USERSELECTION;
	}
	
	cout<<"\nEnter another integer:";
	cin>>Num2;
	cout<<"\nNum1 is "<<Num1<<".";
	cout<<"\nNum2 is"<<Num2<<".";
	cout<<"\nDo you wish to change these numbers?";
	
	
	
	
	RESULTDISPLAY://Result Display
	cout<<"\nWELCOME TO RESULT DISPLAY";
	cout<<"\n\t Your Result is";
	cout<<Result<<"\n";
	cout<<"Result2 is "<<Result2<<"\n";
	cout<<"Goodbye!!!!!";	
	
	
	return 0;
}

I can't figure out what to do to get decimals in division...
It also gets stuck after the operation 'd' for division. ?
for decimals instead of integers, use doubles. they can use decimals. You could also add a place for remainders in division.
I have My own version here:
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
#include <Windows.h>
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
    string retry;
    string symbol;
    string word;
    int a = 0;
    int b = 0;
    int x = 1;
    int Exponent=0;
	double number1=0;
	double number2=0;
	double answer=0;
    void num_input();
    void Answer();
    void exponent();
    bool Retry();
int main(){
do {
	cout << "What type of equation would you like to answer? \n";
	cout << "Please type the word for the equation you would like to complete \nNO CAPS!\n";
	cin >> word;

             if (word == "add"){
			cout << "You have chosen Addition" << endl;
			symbol="+";}
		else if(word == "subtract"){
			cout << "You have chosen Subtraction" << endl;
			symbol="-";}
		else if(word == "divide"){
			cout << "You have chosen Division" << endl;
			symbol="/";}
		else if (word == "multiply"){
			cout << "You have chosen Multiplication" << endl;
			symbol="*";}
		else if(word == "exponent"||word == "exponents"){
                        cout << "You have chosen Exponents"<< endl;
                        symbol="^";}
		else{
			cout << "You have not followed my instructions, the program will now Restart!" << endl;
			Sleep(2000);
			system("cls");
			continue; }
               num_input();
               Answer();
} while (x=1);
num_input();}
void num_input(){
	cout << "Please type your 1st number" << endl;
	cin >> number1;
	cout << "Please type your 2nd number or Exponent" << endl << endl;
	cin  >> number2;

	if (symbol == "+")
			answer = number1 + number2;
		else if(symbol == "-")
			answer = number1 - number2;
		else if(symbol == "/")
			answer = number1 / number2;
		else if (symbol == "*")
			answer = number1 * number2;
        else if (symbol == "^")
            Exponent = number2;
            void exponent();

	if (symbol == "/" && number2 == 0)
	{
			cout << "This is the only formula that is not yet supported, sorry about that! \nThe program will now end!";
			Sleep(2000);
			system("EXIT");
	}else
	Answer();




}
void exponent(){
switch(Exponent){
case 1:
    number1 = answer;
break;
default:
    break;
}
}
void Answer(){
	cout << "Your equation is:" << endl;
	cout << number1 << " " << symbol << " " << number2 << " = " << answer;
    cout << "\nyour answer is " << answer << endl << endl << endl;
	cout << "Thank you for using The 4 Equation Calculator, made by jasonwynn10!" << endl;
	x=0;
	Retry();}
bool Retry(){
    Sleep(5000);
    cout << "Press SpaceBar to restart or wait 5 seconds for the program to close.\n\n";
    while(b!=1){
    if(GetAsyncKeyState(VK_SPACE)){
    a=1;
    x=1;
    system("CLS");
    main();
    }else{
    Sleep(1000);
    if(b=5){system("exit");}
    b++;}}
    }

I have an even more insane crazy calculator that can do all kinds of problems for you. I am currently working on the Graphing part of it.
Last edited on
to myself

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
//Selctable calculator
/* with fixes labeled below
XVIII
*/
#include<iostream>
#include<string>
using namespace std;
int main()
{
	cout<<"\nCalculator 2.0";
	cout<<"\nThe calculator where you can select the op.";
	cout<<"\nEnter one integer:";
	int Num1=0;
	int Num2=0;
	int Result=0;
	string Result2;
	cin>>Num1;
	USERSELECTION:
	cout<<"\nEnter the operation.";
	cout<<"Enter 'm' to multiply, 'd'to divide, 'a' to add,\n";
	cout<<"'s' to subtract, 'c' to square, & 'q' to cube\n";
	char Userselection= '\0';
	cin>>Userselection;
	{
	if (Userselection=='c')
	{
	    Result=Num1*Num1;
	    goto RESULTDISPLAY;
	}
	
	else if(Userselection=='q')
	{
	    Result=Num1*Num1*Num1;
	    goto RESULTDISPLAY;
	}
	
	else if(Userselection=='m')
	Result=Num1*Num2;

	else if (Userselection=='d')
	{
	    Result=Num1 / Num2;
	    cout<<"\n\t Your Result is";
	    cout<<Result<<"\n";
    	cout<<"Result2 is "<<Result2<<"\n";
    	cout<<"Goodbye!!!!!";
	}
	else if (Userselection=='a')
	Result=Num1+Num2;

	else if (Userselection=='s')
	Result=Num1-Num2;

	else
	{
		cout<<"\nYou entered an invalid answer. Try again.";
		goto USERSELECTION;
	}
	}
	cout<<"\nEnter another integer:";
	cin>>Num2;
	cout<<"\nNum1 is "<<Num1<<".";
	cout<<"\nNum2 is"<<Num2<<".";
	cout<<"\nDo you wish to change these numbers?";
	
	
	
	
	RESULTDISPLAY://Result Display
	cout<<"\nWELCOME TO RESULT DISPLAY";
		
	
	
	return 0;
}
Topic archived. No new replies allowed.