Cpp - Output message and random number

Description

Output message and random number

Demo

#include <iostream>      
#include <string> 

#include <cstdlib>       // Prototypes of functions 
// void srand( unsigned int seed); 
// int rand(void); 
// or: //www. j a  va2  s.  co  m
// #include <stdlib.h> 

using namespace std;   // Introduces all names of namespace 
             // std into the global scope. 
int main()
{
  string message = "\nLearn from your mistakes!";// = 
    cout << message << endl;

  int len = message.length();
  cout << "Length of the string: " << len << endl;

  // And another random number: 
  int b;
  srand(12);
  b = rand();
  cout << "\nRandom number: " << b << endl;
  return 0;
}

Result

Related Exercise