Need help fixing program.

The point of the program is a guessing game. The program chooses a number between 1-100 and the user guesses. If they guess too high it says 1, too low it says -1 and correct guess a 0. Then it outputs the number of tries it took. It works, but my teacher says that i should be using a == instead of =, and also the use of else instead of else if. Im lost on how to fix it. Please help.

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
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main(){
    int number, guess, trials = 0;
    srand(time(0));
    number = rand() % 100 + 1;
    cout << "Guess the number. If correct you will get a 1, wrong a -1, and correct a 0." << endl;
    do{
        cout << "Please enter a value between 1 and 100." << endl;
        cin >> guess;
        ++trials;
    
        if (guess > number){
            cout << "1" <<endl;
        }
        else if (guess < number){
            cout << "-1" <<endl;
        }
        else if (guess = number){
            cout << "0" <<endl;
            cout << "Congrats you did it in " << trials << " tries" << endl;
        }
        
    } while (guess != number);
    
    system("pause");
}
Hint

== : check to see if both left and right are equal

= : assign a value to a variable.
thank you and what about the else if, else thing. Idk how ot change it to else
It checks if 'guess' is greater than or less than 'number', and if it is neither than in must be equal to 'number'. So, a simple 'else' statement will do.
Topic archived. No new replies allowed.