Problems with my calculator

I keep getting errors in the following code (I will be posting the errors at the bottom of the 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
  #include <iostream>
#include <stdlib.h>
#include <conio.h>


using namespace std;

int main()
{
    int n1;
    int n2;
    int choice;
    int  sign;

    cout << "Welcome To My Calculator!" << endl;
    cout << "Would you like to continue the program?" << endl;
    cout << "Enter Yes, or No" << endl;
    cin >> choice;

    getch();

    if (choice = 'Yes') {

    system("cls");

    cout << "To use this application you will: ";
    cout << "Press 1 for addition" << endl << endl;
    cout << "Press 2 for subtraction" << endl << endl;
    cout << "Press 3 for multiplication" << endl << endl;
    cout << "Press 4 for division" << endl << endl;
    cout << "You can now choose your desired operation:";

    cin >> sign;

    cout << "Press ENTER twice to be prompted to select two numbers:";

    getch ();

    cout << "Enter your first number:";

    cin >> n1;

    cout << endl;
    cout << "Enter your second number:";

    cin >> n2;

    cout << endl;

   switch (sign) {
   case 1:
       cout << n1 + n2 "=" << endl;
       break;

   case 2:
   cout << n1 - n2 "=" << endl;
   break;

    case 3:
        cout << n1 * n2 "=" << endl;
        break;

    case 4:
        cout << n1 / n2 "=" << endl;
        break;}

    /*cout << "Press ENTER twice to be prompted to select two numbers:"

    getch ();

    cout << "Enter your first number:";

    cin >> n1;

    cout << endl;
    cout << "Enter your second number:"

    cin >> n2;

    cout << endl;*/
    }



}


||=== Build: Debug in Project 1 (compiler: GNU GCC Compiler) ===|
D:\My Documents\Code Blocks Projects\Project 1\main.cpp|22|warning: multi-character character constant [-Wmultichar]|
D:\My Documents\Code Blocks Projects\Project 1\main.cpp||In function 'int main()':|
D:\My Documents\Code Blocks Projects\Project 1\main.cpp|22|warning: suggest parentheses around assignment used as truth value [-Wparentheses]|
D:\My Documents\Code Blocks Projects\Project 1\main.cpp|52|error: expected ';' before string constant|
D:\My Documents\Code Blocks Projects\Project 1\main.cpp|56|error: expected ';' before string constant|
D:\My Documents\Code Blocks Projects\Project 1\main.cpp|60|error: expected ';' before string constant|
D:\My Documents\Code Blocks Projects\Project 1\main.cpp|64|error: expected ';' before string constant|
||=== Build failed: 4 error(s), 2 warning(s) (0 minute(s), 2 second(s)) ===|

there are alot of errors in this code im trying to sort through them as i go, looking up what i need, but i cannot seem to find whats wrong. Any help is much appreciated. Any pointers on how to improve my code, or anything i need to change would also be helpful...

I have the bottom commented out because i was experimenting with something by the way...
Last edited on
Lines 52, 56, 60 and 64 have syntax errors.

They should look like:
1
2
3
4
5
6
7
cout << n1 + n2 << "=" << endl;

cout << n1 - n2 << "=" << endl;

cout << n1 * n2 << "=" << endl;

cout << n1 / n2 << "=" << endl;


Hope this helps!
Thanks for the help! I have now run into another problem, whenever I compile it, sometimes it work i'd sat 1/10 times, it just prints everything out ignoring every cin >> i use. Any help is appreciated.
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
#include <iostream>
#include <stdlib.h>
#include <conio.h>


using namespace std;

int main()
{
    int n1;
    int n2;
    int choice;
    int  sign;

    cout << "Welcome To My Calculator!" << endl;
    cout << "Would you like to continue the program?" << endl;
    cout << "Enter Yes, or No" << endl;
    cin >> choice;

    

    if (choice = 'Yes') {

    system("cls");

    cout << "To use this application you will:" << endl;;
    cout << "Press 1 for addition" << endl << endl;
    cout << "Press 2 for subtraction" << endl << endl;
    cout << "Press 3 for multiplication" << endl << endl;
    cout << "Press 4 for division" << endl << endl;
    cout << "You can now choose your desired operation:";
    cout << endl << endl;

    cin >> sign;

    

    cout << "Press ENTER twice to be prompted to select two numbers:" << endl;
    
   getch ();


    cout << "Enter your first number:";

    cin >> n1;

    cout << endl;
    cout << "Enter your second number:";

    cin >> n2;

    cout << endl;

   switch (sign) {
   case 1:
       cout << n1 + n2  << endl;
       break;

   case 2:
   cout << n1 - n2  << endl;
   break;

    case 3:
        cout << n1 * n2  << endl;
        break;

    case 4:
        cout << n1 / n2  << endl;
        break;}



    }



}
Both n1 n n2 are int types try using this :
 
cout<<(float)(n1/n2)<<endl;

And you should check if the denominator isnt zero.Computers are a badaaas with infinity.
Also making n1 and n2 signed might help in minus operator if n2 is greator thn n1.
Topic archived. No new replies allowed.