#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.
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*
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++).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With