From now on, I will begin to learn C++, starting with C++ primer. What is a program? Programs usually contain algorithms and data sets. Algorithms or instructions tell you how to do this. Data sets are operational objects. For example, eating, rest and so on can be regarded as algorithms, sometimes the algorithm involves more than one object of operation.A simple C++ program has been listed below.
#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
void sleep(void){ cout<<"sleep"<<endl;}
void eat(void){ cout<<"eat"<<endl;}
void study(void){ cout<<"study"<<endl;}
int main()
{
int i=1;
while(1)
{
cout<<"The loop count:"<<i<<endl;
srand((unsigned)time(NULL));
int a;
a=rand()%(3-0+1)+0;
cout<<"a="<<a<<endl;
if(a>2||a<0) cout<<"error!"<<endl;
if(a==0) sleep();
if(a==1) eat();
if(a==2) study();
//else cout<<"error"<<endl;
i++;
for(int j=0;j<1000000000;j++);
}
}
Reference
【1】https://blog.csdn.net/beyond0824/article/details/6009908
【2】https://blog.csdn.net/u014571489/article/details/82258467
【3】https://blog.csdn.net/qq_21808961/article/details/78204418