I don't really understand why it's returning a segmentation fault... I'm sorry. Can someone please explain to me what I did wrong here? I have the main method ask questions before it calls the input method to create new structs that will be passed to the multiFunction, which will multiply the fractions. I try to have it passed to the outputFunction to print it, but that doesn't seem to want to work.
struct rational {
int firstNum;
int secondNum;
int result;
};
void inputFunction(struct rational ratNum);
void outputFunction(struct rational ratNum);
void addFunction(struct rational one, struct rational two);
void multFunction(struct rational one, struct rational two);
void inputFunction (struct rational ratNum){
ratNum.firstNum = 0;
ratNum.secondNum = 0;
printf("Enter the first int: ");
scanf("%d", &ratNum.firstNum);
printf("Enter the second int: ");
scanf("%d", &ratNum.secondNum);
}
void outputFunction(struct rational ratNum){
printf("Output: %d /", ratNum.firstNum);
}
void multFunction (struct rational one, struct rational two){
struct rational ratNum;
ratNum.firstNum = 0;
ratNum.secondNum = 0;
ratNum.result = 0;
int resultNum = one.firstNum * two.firstNum;
int resultNum2 = one.secondNum * two.secondNum;
ratNum.firstNum = resultNum;
ratNum.secondNum = resultNum2;
int result = resultNum / resultNum2;
ratNum.result = result;
outputFunction(ratNum);
}
int main(void){
struct rational ratNum;
char yesNo = 'y';
int choice = 0;
while(yesNo == 'y'){
printf("Do you want to run the program (y/n): ");
scanf("%c", &yesNo);
inputFunction(ratNum);
struct rational firstRational;
firstRational.firstNum = ratNum.firstNum;
firstRational.secondNum = ratNum.secondNum;
inputFunction(ratNum);
struct rational secondRational;
secondRational.firstNum = ratNum.firstNum;
secondRational.secondNum = ratNum.secondNum;
printf("Enter 1 for add and 2 for multiply: ");
scanf("%d", &choice);
if(choice == 1){
addFunction(firstRational, secondRational);
}
else if(choice = 2){
multFunction(firstRational, secondRational);
}
printf("Do you want to run the program again (y/n): ");
scanf("%c", yesNo);
}
}