C Programming Question I\'m not sure if I worded my question properly, but here
ID: 3672538 • Letter: C
Question
C Programming Question
I'm not sure if I worded my question properly, but here is what I'm basically looking for. I'm currently working on an assignment for school practicing using functions in my code. I'm having trouble reusing a certain function by altering the operation in the function. I've already declared all the variables above, but for the sake of keeping this short I didn't include.
printf("What is %d %d %d: ", j, Operation, k);
/* What goes here for the answer formula */
scanf("%d", &Choice);
Depending on what I need for my operation whether it's +, -, /, *, etc. how would I code it under the printf line. I've already tried:
Answer = j Operation k;
Which I know is wrong, but figured I'd try. Again, not sure if this is even possible or would I need to just create a separate function for each operation? Thank you!
Explanation / Answer
you should use a if else check of operarion or switch like this:
if(operation=="+"){
answer = j + k;
}
if(operation=="-"){
answer = j - k;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.