Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- int x = 1 + rand() % 100;
- int guessed, counter = 0;
- cout << "The number has been drawn. Try to guess!\n";
- do
- {
- cin >> guessed;
- if(guessed > x)
- cout << "Your number is too large :( ";
- if(guessed < x)
- cout << "Your number is too small :( ";
- ++counter;
- } while(guessed != x);
- cout << "Congratulations! You needed " << counter << " attempts to guess the number " << x << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement