help with class

the error is on line ,12, how do i fix them...they are expected unqualified-id before '}' token ,and expected `,' or `;' before '}' token and, expected declaration before '}' token

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
#include <iostream>

using namespace std;

class setup{
    public:
    void setupandtitle(){
         cout << "hello";
         }
         }
    
};

int main()
{
    int a;
    int b;
    char cchar;
    char again;
    
    do{
    system("CLS");
    
    cout << "please enter the first number you want to use" << endl;
    cin >> int a;
    cout << "please enter the number you would like to use" << endl;
    cin >> cchar;
    cout >> "please enter the second number you would like to use" << endl;
    cin >> int b;
    
    switch (cchar){
           
           case '+':
                cout << "the answer is: " << dnumber1 << " + " << dnumber2 << " = "
                << (dnumber1 + dnumber2) << endl;
                break;
           case '-':
                cout << "the answer is: " << dnumber1 << " - " << dnumber2 << " = "
                << (dnumber1 - dnumber2) << endl;
                break;
           case '*':
                cout << "the answer is: " << dnumber1 << " * " << dnumber2 << " = "
                << (dnumber1 * dnumber2) << endl;
                break;
           case '/':
                cout << "the answer is: " << dnumber1 << " / " << dnumber2 << " = "
                << (dnumber1 / dnumber2) << endl;
                break;
           default:
                cout << "you cant use that operation";
                break;
                }
                cout << "would you like to start again (y or n)";
           cin >> cagain;
           }while (cagain == 'y' || cagain == 'Y');
           
    system("pause");
    return 0;
}

    
1
2
3
4
5
6
7
8
class setup{
    public:
    void setupandtitle(){
         cout << "hello";
         }
         }
    
};


Try counting the braces. What exactly is that last brace closing?
oh thanks
ok it works now but why doesnt it print "hello!!!, IM A CALCULATOR... lets get started"????


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
#include <iostream>

using namespace std;

class setup{
    public:
    void title(){
         cout << "hello!!!, IM A CALCULATOR... lets get started" << endl << endl;
         }
};
    


int main()
{
    system("TITLE calculator");
    system("color 2");
    double a;
    double b;
    char cchar;
    char cagain;
    
    do{
    system("CLS");
    
    cout << "please enter the first number you want to use" << endl;
    cin >> a;
    cout << "please enter the number you would like to use" << endl;
    cin >> cchar;
    cout << "please enter the second number you would like to use" << endl;
    cin >> b;
    
    switch (cchar){
           
           case '+':
                cout << "the answer is: " << a << " + " << b << " = "
                << (a + b) << endl;
                break;
           case '-':
                cout << "the answer is: " << a << " - " << b << " = "
                << (a - b) << endl;
                break;
           case '*':
                cout << "the answer is: " << a << " * " << b << " = "
                << (a * b) << endl;
                break;
           case '/':
                cout << "the answer is: " << a << " / " << b << " = "
                << (a / b) << endl;
                break;
           default:
                cout << "you cant use that operation";
                break;
                }
                cout << "would you like to start again (y or n)";
           cin >> cagain;
           }while (cagain == 'y' || cagain == 'Y');
           
    system("pause");
    return 0;
}
You seem to misunderstand the point of classes. But the technical reason is because you never create a setup object and call the title() method anywhere.
what dont i get about classes and i dont get what you mean. And im not trying to make cllases useful im trying to learn them..
Last edited on
just add the following in begging of main()
and wil work correctoly.
1
2
3

setup setapp1;
setup.title()

i did that and this error came up. and can you explain that to me 17 expected primary-expression before '.' token

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
#include <iostream>

using namespace std;

class setup{
    public:
    void title(){
         cout << "hello!!!, IM A CALCULATOR... lets get started" << endl << endl;
         }
};
    


int main()
{
    setup setapp1;
    setup.title();
    system("TITLE calculator");
    system("color 2");
    double a;
    double b;
    char cchar;
    char cagain;
    
    do{
    system("CLS");
    
    cout << "please enter the first number you want to use" << endl;
    cin >> a;
    cout << "please enter the number you would like to use" << endl;
    cin >> cchar;
    cout << "please enter the second number you would like to use" << endl;
    cin >> b;
    
    switch (cchar){
           
           case '+':
                cout << "the answer is: " << a << " + " << b << " = "
                << (a + b) << endl;
                break;
           case '-':
                cout << "the answer is: " << a << " - " << b << " = "
                << (a - b) << endl;
                break;
           case '*':
                cout << "the answer is: " << a << " * " << b << " = "
                << (a * b) << endl;
                break;
           case '/':
                cout << "the answer is: " << a << " / " << b << " = "
                << (a / b) << endl;
                break;
           default:
                cout << "you cant use that operation";
                break;
                }
                cout << "would you like to start again (y or n)";
           cin >> cagain;
           }while (cagain == 'y' || cagain == 'Y');
           
    system("pause");
    return 0;
}

    





The name of your created object is setapp1


setup.title();
should be
setapp1.title();

i did that and it still wont print what i have in the class

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
#include <iostream>

using namespace std;

class setup{
    public:
    void title(){
         cout << "hello!!!, IM A CALCULATOR... lets get started" << endl << endl;
         }
};
    


int main()
{
    setup setapp1;
    setapp1.title();
    system("TITLE calculator");
    system("color 2");
    double a;
    double b;
    char cchar;
    char cagain;
    
    do{
    system("CLS");
    
    cout << "please enter the first number you want to use" << endl;
    cin >> a;
    cout << "please enter the number you would like to use" << endl;
    cin >> cchar;
    cout << "please enter the second number you would like to use" << endl;
    cin >> b;
    
    switch (cchar){
           
           case '+':
                cout << "the answer is: " << a << " + " << b << " = "
                << (a + b) << endl;
                break;
           case '-':
                cout << "the answer is: " << a << " - " << b << " = "
                << (a - b) << endl;
                break;
           case '*':
                cout << "the answer is: " << a << " * " << b << " = "
                << (a * b) << endl;
                break;
           case '/':
                cout << "the answer is: " << a << " / " << b << " = "
                << (a / b) << endl;
                break;
           default:
                cout << "you cant use that operation";
                break;
                }
                cout << "would you like to start again (y or n)";
           cin >> cagain;
           }while (cagain == 'y' || cagain == 'Y');
           
    system("pause");
    return 0;
}

    
i did that and it still wont print what i have in the class


It does on mine (once I rip out those systems).
Line 26 is clearing the screen, which will happen pretty quickly after your title message has been displayed.
ok thx
Topic archived. No new replies allowed.