I don't understand why this program will not compile please help.
This is what the program supposed to do.

After the correct number is guessed or all five guesses are used and the correct number is not guessed, the user will see a message that shows the secret number and tells how many guesses were used.

Ask the user if he wants to play again. If yes, repeat steps 2 through 5. If not, thank the user for playing and end the program.

#include <iostream>
using namespace std;

int main()
    system("color 4");
    int number, ans;

      number = rand() % 100 + 1;

      int guess, tries=5;

      do {
            cout << "Can you guess my secret number? You have 5 tries, (1-100). "<< endl;
            cout << "Enter guess number: ";

            cin >> guess;

            if (guess < number)

                  cout << "Too low, try again!" << endl;

            else if (guess > number)

                  cout << "Too high, try again!" << endl;

            else if (guess == 42);

                  cout << "Your guess is right!" << endl;

           if (tries > 5)
           cout << "You haven't guess my secret number. The secret number is 42. Would you like to start again?";
           cout << "Press 'Y' or 'y', " << endl;
           cin >> ans;
           else if (ans != 'Y' || ans != 'y')
              goto restart;


Oh good god, I don't even know where to begin:
-why do you need a goto statement? a loop would do just fine
-you are closing a nonexistent brackets
-42 is not the random number you generated
-and you also have improper brackets
-don't forget srand(time(0));

anyways, a simplified code would be like

int main() {
int guess,ans,try;
bool game = false;
char ag;

while(!game) {
if(try == 0)
ans = rand()%100+1;

cout<<"guess a number";

if(ans == guess) {
cout<<"you win! try again?y/n";

if(ag == 'y')

cout<<"wrong answer, try again"



return 0;

this wont tell if the answer is too high or too low, but I'll leave that to you. Good luck.

commented: Good advice. +21
commented: Good job! +1