Am I doing this the C++ way? I am trying to write a program that reads in
two values send them to a function and calulates if the second is a multiple
of the first. It compiles fine, but i get a seg fault and a warning about
an integer to a cast. I belive the problem is in the return statements but I
am having trouble decipering what I am doing wrong
Code:
#include <stdio.h>
#include <string.h>
/*function prototype*/
char isMultiple ( int, int );
/*main function - begins program execution -----------------------------------*/
int main ( void )
{
int num1;
int num2;
printf("Enter two values: ");
scanf("%d %d", &num1, &num2);
printf("\nResult is: %s", isMultiple ( num1, num2));
getch(); /*freeze console output window*/
return 0; /*return value from int main*/
}
/*function to define if second is a multiple of the first*/
char isMultiple ( int x, int y )
{
char result1[ 35 ];
char result2[ 20 ];
strcpy(result1, "First is a multiple of second");
strcpy(result2, "No multiple found");
if (( x % y ) == 0 )
{
return result1;
}
else
{
return result2;
}
}