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

need help doing a prefix calculator code in c programming that have the fallowin

ID: 674027 • Letter: N

Question

need help doing a prefix calculator code in c programming that have the fallowing: need help with this asap please

Print instructions explaining how to operate the calculator

Allow the user to continue entering calculations until they quit the program

Allow the user to perform the following operations:

add ( + ) should add to doubles

subtract ( - ) should subtract to doubles

multiply ( * ) multiply two doubles

divide ( / ) divide two doubles, do not allow division by zero

power ( ^ ) a double and an integer, calculate the double raised to the integer. zero and negative exponents should work.

exponential ( e ) raise the constant e to the power of the integer provided. zero and negative exponents should work. (you must define the constant)

factorial ( ! ) given an integer, calculate the factorial. store your result as a long

random range ( r ) given two integers, generate a random integer between the two integers (inclusively). Be sure the lower bound is less than the upper bound

sum range ( s ) calculate the sum of consecutive integers between two given integers (inclusively)

round ( ~ ) given a double, round to the nearest integers

roundup ( ' ) given a double, round to the nearest integers

rounddown ( _ ) given a double, round to the nearest integers

minimum ( < ) given two doubles, determine the lesser

maximum ( > ) given two doubles, determine the greater

Allow the user to input the calculation all at once (examples below)

+ 3 4

/ 4.3 2.3

^ 3.1 2

r 5 10

Your code must meet the following technical specifications

use at least two variables of different types

no global variables allowed

use a constant, global constants are ok

use at least one if or if else statement

use at least one switch statement

use at least one for loop

use at least one while or do while loop

use at least three functions with prototype.

at least one must return a value

at least one must take input

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    printf("+ double double: will add the two values ");
        printf("- double double: will subtract the two values ");
        printf("* double double: will multiply the two values ");
        printf("/ double double: will divide the two values ");
        printf("/ double double: will divide the two values ");
        printf("^ double integer: will give double raised to the integer ");
        printf("e integer: will give e to the power of the integer ");
        printf("i integer: will give factorial of the integer ");
        printf("r integer integer: generate a random integer between the two integers (inclusively) ");
        printf("s integer integer: generate sum of consecutive integers between two given integers (inclusively) ");
        printf("~ double: round to the nearest integers ");
        printf("' double: round to the nearest upper integer ");
        printf("_ double: round to the nearest lower integer ");
        printf("< double double: will give the lesser of the two values ");
        printf("> double double: will give the higher of the two values ");
        printf("q : quit the program ");
    while(1)
    {
        char ch;
        double d1,d2;
        int n1,n2,i,j,k;
        long fact;
        int quit=0;
        scanf("%c",&ch);
        switch(ch)
        {
            case '+':
                scanf("%lf",&d1);
                scanf("%lf",&d2);
                printf("%lf ",d1+d2);
                break;
            case '-':
                scanf("%lf",&d1);
                scanf("%lf",&d2);
                printf("%lf ",d1-d2);
                break;
            case '*':
                scanf("%lf",&d1);
                scanf("%lf",&d2);
                printf("%lf ",d1*d2);
                break;
            case '/':
                scanf("%lf",&d1);
                scanf("%lf",&d2);
                if(d2==0)
                {
                    printf("Cannot divide by zero ");
                }
                else
                {
                    printf("%lf ",d1/d2);
                }
                break;
            case '^':
                scanf("%lf",&d1);
                scanf("%d",&n1);
                printf("%lf ",pow(d1,n1));
                break;
            case 'e':
                scanf("%d",&n1);
                printf("%lf ",pow(M_E,n1));
                break;
            case '!':
                scanf("%d",&n1);
                fact=1;
                for(i=2;i<=n1;i++)
                    fact=fact*i;
                printf("%ld ",fact);
                break;
            case 'r':
                scanf("%d",&n1);
                scanf("%d",&n2);
                if(n1>n2)
                {
                    printf("lower bound must be less than upper bound ");
                }
                else
                {
                    i = rand();
                    i = n1 + ((i*(n2-n1))/RAND_MAX);
                    printf("%d ",i);
                }
                break;
            case 's':
                scanf("%d",&n1);
                scanf("%d",&n2);
                j=0;
                if(n1<=n2)
                {
                    for(i=n1;i<=n2;i++)
                        j+=i;
                }
                else
                {
                    for(i=n2;i<=n1;i++)
                        j+=i;
                }
                printf("%d ",j);
                break;
            case '~':
                scanf("%lf",&d1);
                i = d1+0.5;
                printf("%d ",i);
                break;
            case ''':
                scanf("%lf",&d1);
                i = d1+1;
                printf("%d ",i);
                break;
            case '_':
                scanf("%lf",&d1);
                i = d1+0;
                printf("%d ",i);
                break;
            case '<':
                scanf("%lf",&d1);
                scanf("%lf",&d2);
                if(d1<=d2)
                    d2=d1;
                printf("%lf ",d2);
                break;
            case '>':
                scanf("%lf",&d1);
                scanf("%lf",&d2);
                if(d1<=d2)
                    d1=d2;
                printf("%lf ",d1);
                break;
            case 'q':
                printf("quitting ");
                quit=1;
                break;
       }
       if(quit==1)
           break;
    }
}