Help -- I am teaching myself C through a book and one of the exercises calls for you to write a program that has a function which calls two other functions. I wrote the following code and compiled it with DevC++, Pelles C, and Quincy 99. None of them gave me any warnings or errors but the compiled program (from any of the above 3 compilers) will not run on Windows XP or Windows 98. The code is as follows:
Code:
/* This program asks whether or not you want to multipy or divide then */
/* performs the calculation */
#include <stdio.h>
char g;
int a, b, c, t, s;
int x,y,w,z;
int calculate(int x, int y );
int product(int w,int z );
int divide(int w,int z);
int main( void )
{
printf("This program will multiply two numbers or\n");
printf("divide the first number by the second.\n");
printf("Press 1 if you want to multiply\n");
printf("Press 2 if you want to divide: ");
scanf("%d", g);
printf("\nEnter in the first number: ");
scanf("%d", a);
printf("\nEnter in the second number: ");
scanf("%d", b);
c = calculate( a, b );
if (g == 1)
{
printf("Their product is: %d\n", c);
}
else
{
printf("%d divided by %d is %d.\n\n", a, b, c);
}
system("PAUSE");
return 0;
}
int calculate( x, y )
{
if (g == 1)
{
t = product( x, y );
}
else
{
t = divide( x, y);
}
return t;
}
int product( w, z )
{
s = ( w * z);
return s;
}
int divide( w, z)
{
s = ( w * z);
return s;
}
When I run the program I encounter the error after I enter a value when prompted to enter 1 or 2.
Any help would be very welcome. And please forgive my programming ignorance.