I am very new at programming and i am trying to make a guessing game. They are to guess a number between 1 and 1000, and if it is too low, then i ask them to try again and the same if it was too high. I am not sure why my code is not working it keeps coming up as an error "LINK : fatal error LNK1561: entry point must be defined"
#include <iostream>
#include <string>
#include <time.h>
#include <stdlib.h>
using namespace std;
const int MAX_VALUE = 1000;
int main()
{
cout<<"Welcome to Jackpot!"<<endl;
srand((unsigned int)time(NULL));
int randomNumber = rand() % MAX_VALUE;
randomNumber = rand() % MAX_VALUE + 1;
int guess;
do
{
cout<<"Guess a number: "<<endl;
cin>>guess;
int counter=0;
while(true)
{
if (guess > randomNumber)
{
counter= counter +1;
cout<<"Too high!"<<endl;
cout<<"Try again: "<<endl;
cin>>guess;
}
else if (guess < randomNumber)
{
counter= counter +1;
cout<<"Too low!"<<endl;
cout<<"Try again: "<<endl;
cin>>guess;
}
else if (guess == randomNumber)
{
cout<<"Thats correct! It took "<<counter<<" guesses."<<endl;
break;
}
else
{
cout<<"That is not a valid guess, nice try ;)"<<endl;
cout<<"Try again: "<<endl;
cin>>guess;
}
}
}while (guess);
system("pause");
return 0;
}
I made a number of changes. I got your counter working. I don't know how to submit with the line numbers sorry. Yours was the first post I came across after finish reading the tutorials =D