In the prompt2
function I have two if
statements. First adder
will call prompt2
. When I press 'x' or 'X', why does it still go to the first 'if' statement, and then it prints, "Answer is..", even though by pressing x, it should've terminated? Essentially I want it to where if you press 'x' or 'X', the program just terminates. Also I'm not in main
either, so how can I terminate it from a function that isn't main
? If you need more code, I can edit, just let me know.
int prompt2(int sum) {
char choice; // what the user decides, continuing or not
printf("\nBefore you continue, take a look at my number guess written down on paper.");
printf("\nPress 'D' to display the answer or 'X' to exit: " );
scanf("%c", &choice );
if ( choice == 'D' || 'd' ) {
printf("\nAnswer is %d", sum );
}
else if ( choice == 'X' || 'x' ) {
exit(0);
}
return 1;
}
int adder( int x, int y ) {
int sum = 0;
sum = x + y;
printf("new sum is %d\n", sum );
printf(" %d\n+%d\n----\n?", x, y ); // output appropriate line breaks and spacing for equation
prompt2(sum); // function that asks them if they want to see the answer
return sum;
}