Fred Staff
Posts : 33 Join date : 2010-05-27 Age : 31 Location : Oklahoma
| Subject: Simple guessing game Thu Jun 03, 2010 5:24 pm | | | This is only a guessing game. Pretty basic though but try it out - Code:
-
#include<iostream> #include<cstdlib>
using namespace std;
int main() { double guess, chance=1, random; cout << "Enter your guess : "; srand((unsigned)time(0)); random = (rand()%10)+1; while (chance <= 3) { cin >> guess; if (random == guess) { cout << "You're right.." << endl << endl; system("PAUSE"); return 0; } else { cout << "Try again..." << endl; } chance ++; } cout << "The no. was " << random << endl; system("PAUSE"); return 0; } |
|