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();
}

Edited 5 Years Ago by Narue: added code tags and formatting

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;

Edited 5 Years Ago by YAMNA MIDHAT: n/a

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();
}

Edited 5 Years Ago by Narue: added code tags and formatting

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^^

Edited 3 Years Ago by Dani: Formatting fixed

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.

Attachments avatar17893_24.gif 13.3 KB

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.

Comments
agree
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.....

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..

This article has been dead for over six months. Start a new discussion instead.