What do you want to save?
Add Code snippet
New code examples
-
C++ 2022-02-01 21:31:26
c++ random between two values
#include <iostream> #include <ctime> #include <cstdlib> using namespace std; int main() { srand(time(0)); // Initialize random number generator. cout&l... Add solution -
C++ 2021-11-20 07:13:08
c++ guess my number
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { int num, guess, tries = 0; srand(time(0)); //seed random number generator num = rand() % 100 + 1; // random number between 1 and 100 cout <... Add solution -
C++ 2021-11-16 11:56:20
c++ random number 0 to 1
#include <iostream> #include <ctime> #include <cstdlib> using namespace std; int main() { srand(time(0)); // Initialize random number generator. cout&l... Add solution -
C++ 2021-10-11 19:16:09
c++ Determine the start and end of the random number
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { srand(time(0)); for (int i = 0; i <= 10; i++) { int start = 3; int end = 8; cout << start + rand() % (end - start + 1); } } Add solution -
C++ 2021-09-27 16:04:04
can you use rand to read in from an external file inc++
string line; int random = 0; int numOfLines = 0; ifstream File("file.txt"); srand(time(0)); random = rand() % 50; while(getline(File, line)) { ++numOfLines; if(numOfLines == random) { cout << line; } } Add solution