I'm programming a simple program to randomly generate letters and output them to the screen on repeat till you close the window. The program seems to somewhat work but other errors aside I attempted to ad in the delay() function with the dos.h library at the beginning of the loop so the program would not work at such high speed. Despite having included the dos.h library I always get Error code E0020: Identifier "delay" is undefined.
//Include neccessary libraries
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <dos.h>
//Only neccessary variable
int alphanum;
//Main program
int main () {
//Begin loop
while (1 > 0) {
delay(100); //Line where delay error ocuurs
//Generate random number between 1-26
srand(time(NULL));
alphanum = (rand() % 26) + 1;
//Depending on what number is generated, the corresponding letter will be output
if (alphanum == 1) {
std::cout << "A";
}
if (alphanum == 2) {
std::cout << "B";
}
if (alphanum == 3) {
std::cout << "C";
}
if (alphanum == 4) {
std::cout << "D";
}
if (alphanum == 5) {
std::cout << "E";
}
if (alphanum == 6) {
std::cout << "F";
}
if (alphanum == 7) {
std::cout << "G";
}
if (alphanum == 8) {
std::cout << "H";
}
if (alphanum == 9) {
std::cout << "I";
}
if (alphanum == 10) {
std::cout << "J";
}
if (alphanum == 11) {
std::cout << "K";
}
if (alphanum == 12) {
std::cout << "L";
}
if (alphanum == 13) {
std::cout << "M";
}
if (alphanum == 14) {
std::cout << "N";
}
if (alphanum == 15) {
std::cout << "O";
}
if (alphanum == 16) {
std::cout << "P";
}
if (alphanum == 17) {
std::cout << "Q";
}
if (alphanum == 19) {
std::cout << "R";
}
if (alphanum == 20) {
std::cout << "S";
}
if (alphanum == 21) {
std::cout << "T";
}
if (alphanum == 22) {
std::cout << "U";
}
if (alphanum == 23) {
std::cout << "V";
}
if (alphanum == 24) {
std::cout << "X";
}
if (alphanum == 25) {
std::cout << "Y";
}
if (alphanum == 26) {
std::cout << "Z";
}
}
}
SOLVED: I found that delay() cannot work in code blocks and switched to Sleep() from the Windows.h library.