#include <stdio.h>
#include <stdlib.h>
#define p printf
#define s scanf
int x;
int y;
int z;
void divider()
{
z=x/y;
}
int main()
{
s("%d", x);
s("%d", y);
divider();
system ("pause");
return 0;
}
I can compile it, but when I run it and input a value for x the program stops working. :(
I wouldn't bother using defines for printf or scanf. Are you wanting to learn C or C++? C++ uses cout & cin instead of print & scanf. You might find these easier to use, if you a not familiar with pointers.
Your program uses integer division - which won't give the answer you expect. 5 / 3 is 1. So you need to change the type to double.
You should also check for division by zero. To make this easier at this stage, check that y is not less than 0.0001 say, rather than a direct comparison with 0.0.