Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Guess a number in c++
#include <iostream> #include <random> #include <stdlib.h> #include <time.h> int main() { srand(time(NULL)); int number = rand() % 10 + 1; int guess = 0; std::cin >> guess; if(guess == number){ std::cout << "Wow first try!\n"; } else { while(guess != number){ std::cout << "Sorry, " << guess << " is incorrect.\n"; std::cin >> guess ; } } std::cout << "You won! The number was " << number << "."; }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Structured Member Value Access Using Structure Member Pointer and Variadic Templates
😊
hangman
Type deduction in VC++
vector of bool
Hangman
C string literal
Template float/int comparison
Runner-mt
Unicode_wcout
Please log in to post a comment.