4
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1,a,b,c,choice;
do
{
    printf("enter any two numbers\n");
    scanf("%d%d",&a,&b);
    printf("pressing one add the two numbers\nenter one if you want to\n");
    scanf("%d",&choice);
    switch(choice)
    {
        case 1:
            {
                c=a+b;
                printf("the sum of the entered numbers%.1f\n\n:",c);
                break;
            }
        default:
            printf("you have entered an invalid");
            break;
    }
    clrscr();
}
while(i==1);
getch();
}

i do not know cause my classmate is using turbo c and it's fine,for me i am using dev c++ but looks like clrscr(); is not known to the compiler help please.

Samuel
  • 612
  • 2
  • 9
  • 25
  • 8
    So you copied from your classmate! ahh... – Grijesh Chauhan Feb 13 '14 at 09:46
  • nope but what i am trying to mean is clrscr(); is not causing any problem with turbo – Samuel Feb 13 '14 at 09:48
  • 1
    u can use system("cls") in windows or system("clear") in linux – Sakthi Kumar Feb 13 '14 at 09:48
  • 1
    Your classmate and you are making the same mistake. You'd see __incorrect__ results in _certain cases_. (Hint: Try supplying different sets of inputs until you spot the bug.) – devnull Feb 13 '14 at 09:48
  • @sakthi cls is not working or maybe i am using it wrongly tell me the whole syntax. – Samuel Feb 13 '14 at 09:53
  • @geek2 read answer below from Acme – Grijesh Chauhan Feb 13 '14 at 09:58
  • If you mean to port MS DOS code to Windows, you must use Windows libraries instead. [Here's some code](http://stackoverflow.com/questions/9782287/undefined-reference-to-gotoxy-in-c/9783195#9783195). – Lundin Feb 13 '14 at 10:03
  • I am still amazed that people use Turbo C and DOS today ... in the age of free (and good) operating systems ... – Ferenc Deak Feb 13 '14 at 10:22
  • Right answer is just not to use clrscr() in this situation. Why not just print a blank line before continuing to the next loop. Then you can see your results by scrolling the window afterwards. If you clear the screen all the time, that's annoying to the user. – Brandin Feb 13 '14 at 11:43

2 Answers2

10

Your classmate is programming under DOS, obviously you don't ... conio.h comes with Turbo C and DOS ... So, remove the lines

#include<conio.h>

and

clrscr();

and

getch();

to make your program compile ...

... and do not use %.1f to print an int.

... and main() must return int

* and do not copy from your classmate ... he seems to be stuck in the stone age*

Ferenc Deak
  • 34,348
  • 17
  • 99
  • 167
2

From Wiki:

conio.h is a C header file used mostly by MS-DOS compilers to provide console input/output.1 It is not part of the C standard library, ISO C nor is it defined by POSIX

Member functions

kbhit - Determines if a keyboard key was pressed.
getch - Reads a character directly from the console without buffer, and without echo.
getche - Reads a character directly from the console without buffer, but with echo.
ungetch - Puts the character c back into the keyboard buffers.
cgets - Reads a string directly from the console.
cscanf - Reads formatted values directly from the console.
putch - Writes a character directly to the console.
cputs - Writes a string directly to the console.
cprintf - Formats values and writes them directly to the console.
clrscr - Clears the screen.

Compilers provided later than 1989 have prepended an _ to the names, to comply with the requisites of the ANSI C Standard.

conio.h is not part of the C standard. It is a Borland extension, and works only with Borland compilers (and perhaps some other commercial compilers). Dev-C++ uses GCC, the GNU Compiler Collection, as it's compiler. GCC is originally a UNIX compiler, and aims for portability and standards-compliance.

You can use Borland functions this way in Dev C++: Include conio.h to your source, and add C:\Dev-C++\Lib\conio.o to "Linker Options" in Project Options (where C:\Dev-C++ is where you installed Dev-C++).

Sadique
  • 22,572
  • 7
  • 65
  • 91