Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE USE FUNCTIONS--->Step 1: Take the user input and set the current value 0.

ID: 441123 • Letter: P

Question

PLEASE USE FUNCTIONS--->Step 1: Take the user input and set the current value 0. Declare the functions for all the operations. Use switch case to define the menu options. Step 2: It should ask once what operation to perform on the initial value of 0, and then based on that input perform that operation, print out the result, then "loop back" and ask the user what operation they would like to perform next. As a starting point use the sample file provided. THE FINISHED PROGRAM SHOULD LOOK LIKE THIS EXAMPLE: Your current value is 0 Options are: 1. Add 2. Subtract 3. Multiply 4. Divide 9. Exit Please enter an operation -> 1 Please enter the number to be added -> 4 Your current value is 4 Options are: 1. Add 2. Subtract 3. Multiply 4. Divide 9. Exit Please enter an operation -> 4 Please enter the number to be divided -> 3

Explanation / Answer

#include void Menu(); void add(int*); void subtract(int*); void multiply(int*); void divide(int*); int main(){ int choice; int value=0; int num; do{ printf("Your current value is %d ",value); Menu(); scanf("%d",&choice); switch(choice){ case 1: add(&value); break; case 2: subtract(&value); break; case 3: multiply(&value); break; case 4: divide(&value); break; case 9: printf("Exit selected. "); break; default: printf("An invalid choice was entered. "); } }while(choice!=9); system("pause"); return 0; } void Menu(){ printf("1. Add "); printf("2. Subtract "); printf("3. Multiply "); printf("4. Divide "); printf("9. Exit "); printf("Please enter an operation -> "); return; } void add(int *result){ int num; printf("Please enter the number to be added ->"); scanf("%d",&num); (*result)=(*result)+num; return; } void subtract(int *result){ int num; printf("Please enter the number to be subtracted ->"); scanf("%d",&num); (*result)=(*result)-num; return; } void multiply(int *result){ int num; printf("Please enter the number to be multiplied ->"); scanf("%d",&num); (*result)=(*result)*num; return; } void divide(int *result){ int num; printf("Please enter the number to be divided ->"); scanf("%d",&num); (*result)=(*result)/num; return; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote