PDA

View Full Version : Why wont this compile..



Overtime
10-06-2011, 09:34 PM
I just want to know why its giving me to errors on the line where
for ( numGuesses = 0; numGuesses < 5; numGuesses++; )




/////////////////////////////////////////////////////////////////////
//
// Name: James Luna
// Date: 9/29/2011
// Class: CSCI/CMPE 1170.03
// Semester: Fall 2011
// CSCI/CMPE 1370 Instructor: Christine Reilly
//
// Generate a random number and ask the user to guess the number.
// Only allow the user to guess 5 times.
//
/////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstdlib>
#include <time.h>


using namespace std;

int main()
{
int number; // The correct number
int guess; // The user's guess
bool correct = false; // If the user has correctly guessed the number
int numGuesses; // The number of times the user has guessed

// Seed the random generator.
srand(static_cast<int> (time(NULL)));

// Generate a random number between 1 and 100.
number = (rand() % 100) + 1;


//////////////////////////////////////////////
// Start modifying program here

// This is the loop from the original program, where the user is allowed
// an unlimited number of guesses.
// Change this while loop to only allow 5 guesses.
for ( numGuesses = 0; numGuesses < 5; numGuesses++; )
{
cout << "guess the number the computer randomly picked between 1 - 100: ";
cin >> guess;
cout << endl;
}

// Check if the user has guessed the correct number.
// If not, tell him if his guess is too low or too high
if(guess == number)
{
cout << "You guessed right! You won!" << endl;
correct = true;

}

else if(guess < number)
{
cout << "sorry, your guess is too low" << endl;
}
else if (guess > number)
{
cout << "sorry, your guess is too high." << endl;
}



// End of program modifications
//////////////////////////////////////////////

system("pause");

return 0;
}



Nvm im dumb just change



( numGuesses = 0; numGuesses < 5; numGuesses++;)


to



( numGuesses = 0; numGuesses < 5; numGuesses++)


forgot the last update doesnt need the semicolon