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

Write a calculator C PROGRAM program that adds and subtracts. Prompt the user to

ID: 3674436 • Letter: W

Question

Write a calculator C PROGRAM program that adds and subtracts. Prompt the user to enter two values and select an operation to perform. Incorporate a program with five modules and functions named as follows:

calc_driver.c - contains the function main() and the user interface

addition.h - contains the prototype for a function named add()

addition.c - contains the function definition for add()

subtraction.h - contains the prototype for a function named subtract()

subtraction.c - contains the function definition for subtract()

Explanation / Answer

I had executed it under CodeBlocks IDE.

main.c

#include <stdio.h>

#include <stdlib.h>

#include "addition.h"

#include "substraction.h"

int main()

{

    int input,one,two,result;

    do{

            printf("Enter value one: ");

            scanf("%d",&one);

            printf("Enter value two: ");

            scanf("%d",&two);

            printf("1.addition() 2.subtraction() 3.exit() ");

            printf("enter your operation ");

            scanf("%d",&input);

            switch(input){

            case 1:result=addi(one,two);

                printf(" addition is = %d ",result);

                break;

            case 2:result=subt(one,two);

                printf(" subtraction is = %d ",result);

                break;

            case 3:exit(0);

            default : printf("Please enter correct operation ");

            }

    }while(input >=1 && input <=3);

    return 0;

}

subtraction.c

int subt(int a,int b)

{

    return (a-b);

}

addition.c

int addi(int a,int b)

{

    return (a+b);

}

addition.h

int addi(int,int);

substraction.h

int subt(int,int);

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