C++ calculator program

why do i get error: a "}" at the end of my code

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
 #include <cstdio>
#include <cstdlib>
#include <iostream>     // std::cout & std::showpoint
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cfloat>


using namespace std;


class Calculator

	
{

            double num1;
			double num2;
			
			char operation; 

            float solution;
			
public:							//public helps to specify that these members are accessible from any function
            void setvalues()

            {

                        cout<<"Input:";

                        cin>>num1;
						cin>>operation;
                        cin>>num2;

            }

            int addition()

            {

                        solution=num1+num2;
                        return solution;
            }

            int subtraction()

            {

                        solution=num1+num2;
                        return solution;

            }
            

int main() 

	

{

	std::cout.precision (51);

             char operation;
           

            if(operation == '+')

            {

        int solution;
		 
                        Calculator cal;			//helps to create calculator object
                        cal.setvalues();
                        solution=cal.addition();
                        std::cout << std::showpoint <<num1<<" "<<"+"<<" "<<num2<<" "<<"="<<" "<< solution <<endl;    //show decimal point (function )

            }

            else if(operation == '-')

            {

          int solution;

                        Calculator cal;			// helps to create calculator object
                        cal.setvalues();
                        solution=cal.subtraction();
                        std::cout << std::showpoint << num1 << " " << "-" <<" " << num2 << " " << "=" << " " << solution <<endl ; //show decimal point (function )


            }
			
			
            return 0;
}
Your class is missing a closing bracket.

EDIT: Put it at Line 54 if you don't see it. Don't forget the semicolon afterward.
Last edited on
Don't forget to add a semicolon after the closing bracket for your class as well.

Also, your subtraction function is wrong.
after adding the semicolon and brackets and all it still has a compilation error.
#include <cstdio>
#include <cstdlib>
#include <iostream> // std::cout & std::showpoint
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cfloat>


using namespace std;


class Calculator


{

double num1;
double num2;

char operation;

float solution;

public: //public helps to specify that these members are accessible from any function
void setvalues()

{

cout<<"Input:";

cin>>num1;
cin>>operation;
cin>>num2;

}

int addition()

{

solution=num1+num2;
return solution;
}

int subtraction()

{

solution=num1-num2;
return solution;

}


int main()



{

std::cout.precision (51);

char operation;


if(operation == '+')

{

int solution;

Calculator cal; //helps to create calculator object
cal.setvalues();
solution=cal.addition();
std::cout << std::showpoint <<num1<<" "<<"+"<<" "<<num2<<" "<<"="<<" "<< solution <<endl; //show decimal point (function )

}

else if(operation == '-')

{

int solution;

Calculator cal; // helps to create calculator object
cal.setvalues();
solution=cal.subtraction();
std::cout << std::showpoint << num1 << " " << "-" <<" " << num2 << " " << "=" << " " << solution <<endl ; //show decimal point (function )


}


return 0;
}
};
Topic archived. No new replies allowed.