-3

I'm new and I really can't understand the meaning of "not declared in scope" error. I tried declaring these as functions and also by using "" to show a function but it did not compile and run. Here are the errors:

In function 'int main()':

[Error] 'random' was not declared in this scope

[Error] 'sound' was not declared in this scope

[Error] 'delay' was not declared in this scope

[Error] 'nosound' was not declared in this scope

[Error] 'BLINK' was not declared in this scope

[Error] 'textattr' was not declared in this scope

#include<stdio.h>

#include<iostream>

#include<dos.h>

#include<conio.h>

#include<stdlib.h>

using namespace std;
int main ()
{
    int count=50;
    while(count--)
    {
    sound(90*random(10));
    delay(100);
    nosound();
    textattr(random("16")+'a'+BLINK);
    cprintf("KSHITIJ");
    }
}

1 Answers1

1

Looks like you have Turbo C++ code from back in the 1990's. The last version of Turbo C++ was released before standardized C++, so it's missing stuff and does other stuff somewhat oddly. It also contains a large bundle of its own libraries that can't be found anywhere else. It's hard to find decent support these days as you're noticing.

' ' was not declared in this scope

Is your compiler saying, "This name has not been defined." It's usually a prompt that you've missed a header. In this case you have all the right headers, but they don't contain these Turbo C++-only functions. This means you need to find alternatives that are supported with modern compilers.

random can be replaced with std::uniform_int_distribution

sound(90*random(10));
delay(100);
nosound();

Can be replaced with the win32 call beep

textattr and cprintf you're probably better off without. That blink will be a pain in the posterior to re-implement in GCC. There might be a win32 call to do all this, but I've never tried it and am at a loss.

user4581301
  • 33,082
  • 7
  • 33
  • 54