I am having problem with `clrscr' undeclared (first use this function) (Each undeclared identifier is reported only once for each function it appears in.) when I am compiling it in DEV-C++ .....please let help me with these

#include <stdio.h>
#define p print f
#define s scan f
main()
{
    int a,b,sum,product;
    clrscr();
    <<<< this is my problem
    sum = 0
          product = 0
                    printf("Enter First number:")scanf("%d",& a);
    printf("Enter Second number:")scanf("%d",& b);
    sum = a+b;
    product = a*b;
    printf("sum of two number : %d",product);
    getch();
}

Dani AI

Generated

Brief diagnostic summary: the visible errors come from three common beginner problems — simple syntax mistakes (missing semicolons, unmatched parentheses), reliance on non‑portable helper functions/macros, and not using compiler warnings to locate the real fault. The replies already point to those causes; the practical path forward is a small, repeatable debug routine rather than a big rewrite.

A compact debugging workflow that resolves the kinds of errors seen here:

  • Compile with maximal warnings enabled and treat warnings as clues to logic mistakes.
  • Inspect the source line reported by the compiler and the line immediately before it (missing semicolons and stray ) almost always live on the previous line).
  • Replace opaque macros (for example macros that rename standard functions) with the real identifiers while learning. They hide errors.
  • Prefer standard I/O and portable constructs instead of implementation-specific helpers; if a legacy header supplies a function, document that dependency.

A useful compiler command to adopt (MinGW/GCC or similar) is:

gcc -std=c11 -Wall -Wextra -pedantic -o simple simple.c

Those flags show warnings that point straight to missing semicolons, mismatched parentheses and other issues. When running input calls, check the input function’s return value to detect bad input instead of assuming success.

Notes tying the thread together: ’s cleaned example demonstrates robust input handling and clearer layout; ’s advice to retype and count parentheses is exactly the right mechanical check for the “expected ‘;’ before ‘)’ token” error; correctly called out the stray extra parenthesis in getchar());; and represent the two sides of using non‑standard headers — available sometimes, but not portable. For sustained learning, pair attention to compiler diagnostics with a modern C tutorial or textbook and an editor that highlights syntax errors as they are typed.

Recommended Answers

All 13 Replies

I am having problem with `clrscr' undeclared (first use this function) (Each undeclared identifier is reported only once for each function it appears in.) when I am compiling it in DEV-C++ .....please let help me with these

#include <stdio.h>
#define p print f
#define s scan f
main()
{
int a,b,sum,product;
clrscr();
sum = 0
product = 0
printf("Enter First number:")scanf("%d",& a);
printf("Enter Second number:")scanf("%d",& b);
sum = a+b;
product = a*b;
printf("sum of two number : %d",product);
getch();
}

when I am compiling it in DEV-C++

i think you should put a semicolon like
sum=0;
produt=0;

I just put a semicolon and clrscr(); has an x mark on it...cant figure it out...I'm doing this for my project

it now reads:

#include <stdio.h>
#define p print f
#define s scan f
main()
{
    int a,b,sum,product;
    clrscr();
    sum=0;
    product=0;
    printf("Enter First number:")scanf("%d",& a);
    printf("Enter Second number:")scanf("%d",& b);
    sum=a+b;
    product=a*b;
    printf("sum of two number : %d",product);
    getch();
}

clrscr() is a non-standard function typically declared in the <conio.h> header. Provided your compiler supports both <conio.h> and clrscr(), including that header will fix your error.

However, since your use of clrscr() is nonsensical anyway, my recommendation would be to remove it entirely (and change getch() to getchar()). In fact, your code is quite broken and horrible. Compare it to something better:

#include <stdio.h>

int main(void)
{
    int a, b;
    
    printf("Enter two numbers: ");
    fflush(stdout);
    
    if (scanf("%d%d", &a, &b) != 2) {
        fputs("Invalid input\n", stderr);
    }
    else {
        int sum = a + b;
        int product = a * b;
        
        printf("Sum:     %d\n", sum);
        printf("Product: %d\n", product);
    }
    
    return 0;
}

done with clearing clrscr....the prob now is...
printf("Enter First number:")scanf("%d",& a);

Those are two statements that need to be separated by a sequence point. Might I suggest a semicolon?

printf("Enter First number: ");
scanf("%d", &a);

I had followed your suggestion Ms Narue...now my prob goes with the product = 0
and it goes like this now....

#include <stdio.h>
#define p printf
#define s scanf
main()
{
    int a, b, sum, product;
    sum = 0
          product = 0
                    printf("Enter First number:")
                    scanf("%d",&a);
                    printf("Enter Second number:")
                     scanf("%d",&b);
    sum = a + b;
    product = a * b;
    printf("sum of two number : %d",product);
    getchar());

please correct my wrong actions I am really willing to learn about this^^

You're missing semicolons at the end of your statements. And I have a strong suspicion that your book sucks ass. Please throw it away and get a better one. In the meantime, please read this thread.

I understand being willing to learn, but you're presently going down a path that will make becoming proficient in C extremely difficult.

I can understand at how geniuses feel ( but i dont belong to the geniuses.....I'm just a normal guy^^) when they are ahead of some equations...I reviewed my statement in DEV-C++ and put all semicolons at the end of every statement....now the final prob [ I think ] is this:
Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Documents and Settings\JESSIE\My Documents\SIMPLE C PROGRAM.cpp" -o "C:\Documents and Settings\JESSIE\My Documents\SIMPLE C PROGRAM.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
C:\Documents and Settings\JESSIE\My Documents\SIMPLE C PROGRAM.cpp: In function `int main()':
C:\Documents and Settings\JESSIE\My Documents\SIMPLE C PROGRAM.cpp:16: error: expected `;' before ')' token

Execution terminated....
I've tried getch and getchar thing and the *BENEVOLENT* X mark appears on the getchar());

I can understand at how geniuses feel ( but i dont belong to the geniuses.....I'm just a normal guy^^)

I finally understand Narue's avatar. It is so appropriate for this thread that I am attaching it to this message.

KOFguru, I have a strong feeling that you are out of touch with the code you typed. Computers are not smart enough to magically make it work like you want it to. I will agree with Narue that you need to learn from another source because your approach is wrong.

And to answer your question, look carefully at that line of code. Write it down on a piece of paper if you have to. Look super closely at it. Notice the parenthesis. Count the parenthesis.

Just use the header file
#include<conio.h>
It supports getch().

commented: Bad Advice!!! -4
commented: Senseless -1

Just use the header file
#include<conio.h>
It supports getch().

And what if my compiler doesn't have conio.h? Most of them do not!
Unless it's required, never use non-portable techniques to do things that can be done without tricks like this one. getchar() is the appropriate function to use.

commented: Its a discussion center.ok.....Every one is student here......Truth or right answer comes from a discussion.If I wrong you can tell me.But dont talk like this.It breaks the rules of Daniweb..... +0
commented: agree +13

the format for getchar is
getchar();
and not getchar());
and i do not think that the lines - #define s scanf and #define p printf were necessary since they are not used in your program at all..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.