help with old code - error: expected ')'

this is an old code i found online, that gives an example C++ code on compound interest.

I have problem compiling it to run.

Compiler gives the following errors

error: expected ')'
while (choice! = -99)
^
note: to match this '('
while (choice! = -99)
^

could someone advise me on how i could modify it to make it work?


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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
  #include <iostream>

#include <stdlib.h>

#include <cmath>

using namespace std;

double simple_interest (double principal, double rate, double time);

double compound_interest (double principal, double rate, double time);

double compound_interest_ear (double principal, double rate, double time, double period);

int main ()
{

    double amount, principal, rate, time, interest, R;

    int choice;

    double SI, CI, EAR, Amount, period;

    amount = principal = rate = time = interest = 0.0;

    while (choice! = -99)
    {

        cout << "\n\n\n\n\n";

        cout << "\t\t\tEnter Principal amount:"; cin >> principal;

        cout << "\t\t\tEnter Rate (In percentage):"; cin >> R;

        rate = R/100;

        cout << "\t\t\tEnter Time (In Years):"; cin >> time;

        cout << "\t\t\t" << principal << endl;

        cout << "\t\t\t" << rate << endl;

        cout << "\t\t\t" << time << endl;

        cout << "\t\t\t************ MENU ********************" << endl;

        cout << "\t\t\t1: Simple Interest" << endl;

        cout << "\t\t\t2: Compound Interest" << endl;

        cout << "\t\t\t3: Effective Annual Rate (Compound Interest)" << endl;

        cout << "\t\t\t****************************************" << endl;

        cout << "\t\t\tEnter You Choice:"; cin >> choice;

        if(choice == 3)
        {

            cout << "\t\t\tNo of Period in a Year:"; 
            cin >> period;

        }

    switch(choice)
    {

        case 1:

            SI = simple_interest (principal, rate, time);

            Amount = principal + SI;

            cout << "\n\n\n";

            cout << "\t\t\tSimple Interest =" << " "<< SI << endl;

            cout << "\t\t\tTotal Amount =" << " " << Amount<< endl;

            break;

        case 2:

            Amount = compound_interest(principal, rate, time);

            CI = Amount - principal;

            cout << "\n\n\n";

            cout << "\t\t\tCompound Interest with Principal =" << " "
            << 
            Amount << endl;

            cout << "\t\t\tTotal Compound Interest ="<< " " << 
            CI << endl;

            break;

        case 3:

            Amount = compound_interest_ear(principal, rate, time, period);

            CI = Amount - principal;

            EAR = pow((1 + (rate/period)),period)-1;

            cout << "\n\n\n";

            cout << "\t\t\tCompound Interest with Principal =" << " " << 
            Amount << endl;

            cout << "\t\t\tTotal Compound Interest =" << " " << 
            CI << endl;

            cout << "\t\t\tEffective Annual Rate =" << " " << 
            EAR << endl;

            cout << "\t\t\tNomianal Rate =" << " " << 
            rate << endl;

            break;

        default:

            cout << "\t\t\tSorry ! Try again";

            break;

        }

    cout << "\n\n\n";

    cout << "\t\t\tDo you want to Continue?" << endl;

    cout << "\t\t\tEnter -99 to end" << endl;

    cout << "\t\t\tOr Enter any other number to Continue:"; 
    cin << choice;

    }

    system("PAUSE");

    return EXIT_SUCCESS;

}

// Simple interest

double simple_interest(double principal, double rate, double time)
{

    double SI = principal * rate * time;

    double Amount = principal + SI;

    return SI;

}

// Compound Interest

double compound_interest(double principal, double rate, double time)
{

    double CI;

    double Amount;

    Amount = principal * pow((1 + rate),time);

    return Amount;

}

// Compound Interest with the effective annual rate

double compound_interest_ear(double principal,double rate, double time,double period)
{

    double CI, EAR, Amount;

    period = period * time;

    Amount = principal * pow((1 + (rate/period)),period);

    return Amount;

}
!= is ONE symbol, but 2 letter. putting a space between not gonna work.
thanks jonnin, seems like the example tutorial i found via google is full of little typo errors.

here's a new error i see after correcting the one you helped.


---

error: invalid operands to binary expression ('std::__1::istream' (aka 'basic_istream<char>') and 'int')
cin << choice;


---

would you be able to help me with the above error as well please?



additionally, can the following warnings be ignored?

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/ostream:753:1: note: candidate template ignored: could not match 'basic_ostream' against 'basic_istream'
operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/ostream:760:1: note: candidate template ignored: could not match 'basic_ostream' against 'basic_istream'
operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/ostream:793:1: note: candidate template ignored: could not match 'basic_ostream' against 'basic_istream'
operator<<(basic_ostream<char, _Traits>& __os, char __c)
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/ostream:800:1: note: candidate template ignored: could not match 'basic_ostream' against 'basic_istream'
operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/ostream:807:1: note: candidate template ignored: could not match 'basic_ostream' against 'basic_istream'
operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
The author wrote cin << choice but wanted cin >> choice.

The << and >> are ideograms - arrows representing the direction of data flow. Since cin is a source of character input, data flows out of cin and into choice as in
cin >> choice;
Similarly cout is a destination for character output so the arrows should direct data into it:
cout << choice;
Last edited on
thanks jonnin and mbozzi for helping me with this.

i am grateful
I think you better stop searching and finding code online. There is too much crap around.
Better get a book and start learning from scratch.
I think you better stop searching and finding code online


This. If code that you find online does not work immediately and without a lot of trouble, discard it. There is a lot of good stuff out there. There is a lot of poor stuff that works, too. And there are tons of total garbage that neither works nor makes any sense.

Unless your problem is really, really out there off the beaten path, though, there is likely working code out there you can lift for it. Find something else that works first try.
Topic archived. No new replies allowed.