不了解基本的c ++程序中的错误

Jon*_*ein 2 c++ compiler-errors

#include <iostream>

using namespace std;

int main(void) {
    int number, guess;

    srand(time(NULL));
    number = rand() % 101;

    cout << "Guess a number between 0-100: ";
    cin >> guess;

    if(number > guess) {
        cout << "The number is greater!\n";
    }
    else if(number < guess) {
        cout << "The number is smaller!\n";
    }
    else {
        cout << "Cognratulations! The number is "number"!\n";
    }
    cin-get();

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

error: 'srand' was not declared in this scope
error: 'rand' was not declared in this scope
error :expected ';' before 'number'
Run Code Online (Sandbox Code Playgroud)

Bri*_*ach 11

你需要添加:

#include <cstdlib>
Run Code Online (Sandbox Code Playgroud)

包括srand()rand()

当你需要使用这样的函数时,查看手册页(或谷歌搜索它们)将告诉你需要包含哪些标题.

http://www.cplusplus.com/reference/clibrary/cstdlib/