0

can anyone help me convert my c program so it works on a linux system or mac? thank you.

#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
int c;
int a, b;
char d;
pov:system("cls");
printf("Enter the first number\n");
a=getch()-48;
system("cls");
printf("Enter the function:\n");
d=getch();
system("cls");
printf("Enter the second number\n");
b=getch()-48;
system("cls");
while (0==0)
{
if (d=='*')
{
a=a*b;
}
if (d=='/')
{
a=a/b;
}
if (d=='+')
{
a=a+b;
}
if (d=='-')
{
a=a-b;
}
printf("value is %d \n",a);
printf("Press 'q' to quit, or press other key to repeat data input\n");
c=getch();
if((c=='q')||(c=='Q')) return;
goto pov;
}
}
3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by jephthah
0

> convert my c program so it works on a linux system or mac
Don't use any non standard functions. Dont use conio.h , since that is DOS library. So replace getch() with getchar() since later is standard funtion, though wont work exactly like former(you will have to hit enter). Dont use system("cls") . Again it is dos and windows specific.

0

never use conio.h for anything. that just breaks your program for anythign other than windows.

and never,.ever, ever use "GOTO" statements. and by that i mean never. they're absolutely horrid. use a while or for loop instead.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.