Weird output

Why is it giving me 2 outputs?

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

using namespace std;

int main()
{
    int sms,ammount;
    int contract;
    cout << "How many SMS's do you send per month?" <<endl;
    cin >> sms;

    cout <<"How many do you pay for your messages?"<<endl;
    cin >> ammount;

    cout << "Do you have a contract y\n (y = 1) (n = 2) ?" << endl;
    cin >> contract;

    if (contract = 1){

        sms = sms - 20;
        sms = sms * ammount;
        cout <<"Your bill is R"<<sms<<endl;
        }


    if (contract = 2){

      sms = sms * ammount;
      cout << "Your bill is R"<<sms<<endl;
      }

    return 0;
}
if (contract = 1){

= is the assignment operator
you need the == relational operator here, and on line 26

http://www.cplusplus.com/doc/tutorial/operators/
Last edited on
Topic archived. No new replies allowed.