//my program asks me to write a C++ program that generates a random number between 1-100, and lets the user guess the number until he/she guesses correctly.
//I have every thing done but my loop will not end. I know I have to "update" the loop to end it but I don't know what that means.
#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;
int main()
{
srand(time(NULL)); //the function that generates random numbers
int number=rand()%100+1; //the range of the random numbers
int userguess; //The guess is stored here
int tries=0; //The number of tries stored here
int answer; //The answer to the question is stored here
answer=40;
char endgame;
while(answer==40||answer==40) {
while ((tries<=10) && ((answer==40)|| (answer==30))){
cout<<"Enter a number between 1 and 100 "<<endl;
cin>>userguess;
tries++;
if(userguess==0||userguess>100){
cout<<"Invalid Entry";
break;
}
if(userguess>answer){
cout<<"Your guess is too high Please try again"<<endl;
}
if(userguess<answer){
cout<<"Your guess is too low. Please try again"<<endl;
}
if(tries<10){
cout<<"Tries left: "<<(10-tries)<<endl;
}
if(userguess==answer){
cout<<"Your answer is correct!"<<endl;
break;
}
Please use code tags! [ code ] [ / code ] (without the spaces)
Why is your while loop using while answer == 40 as a condition? Your first while loop is a totally meaningless infinite loop... It's basically a while(true) with nothing in it to stop it. Your loops should not be using while(answer == 40) as a condition either, just use the while(tries < 10) and don't use two loops. There is no reason for nesting loops in this case.
if(userguess==0
You might want to change that to a <= 0. People might put in negative numbers.