- Joined
- Oct 25, 2004
- Location
- 127.0.0.1
Hi, just started programming in c++ done some basics and now im confused. trying to make a lil text guesiing game all works except last bit asking if they wana play again can someone tell me where im going wrong.
Code:
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <ctime>
using namespace std;
int main ( )
{
int guess;
char ans;
srand (time (0));
int random = rand( );
int num = ((random % 100) + 1);
for (int i = 0; i < 100; i++)
{
start:
cout << "Guess a number between 1 and 100: ";
cin >> guess;
if (guess > num)
{
cout << "The number is lower. Try Again!!\n\n";
continue;
}
if (guess < num)
{
cout << "The number is higher. Try Again!!\n\n";
continue;
}
else if (guess == num)
{
cout << "You've guessed correctly!\n\n";
break;
}
}
string again;
cout << "Do you want to play again? y or n" << endl;
cin >> again;
if (again == "y")
goto start
end if;
system("PAUSE");
return EXIT_SUCCESS;
}