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

Build a basic calculator which adds, subtracts, multiplies, dividesand finds the

ID: 3609639 • Letter: B

Question

Build a basic calculator which adds, subtracts, multiplies, dividesand finds the mod two INTEGERS. The program first prompts the userfor an operator (+, -, *, /, %).

Then it prompts for two integers. Then it computes the resultand prints it on the screen. A sample session would be Welcome tothe Calculator program!

Please enter an operator (+, -, *, /, %): - Please enter twointegers separated by a space: 10 20 10 - 20 = -10.00 Do you wantto continueIn?

Press Y for Yes and N for No: Y Please enter an operator (+, -, *,/, %): % Please enter two integers: 21 4 21 % 4 = 1 Do you want tocontinue?

Press Y for Yes and N for No: N Goodbye! Test your program forvarious inputs. Make the program issue a warning message if theuser tries to divide by zero. You can declare the result to be oftype float and the two numbers to be of type int.

Print the result as a floating point number with totalpositions 8 with 2 positions after the decimal point. Print the twonumbers with a decimal format of 4 positions and the operator with3 positions.

Change your program in the following way: Write your programso that your sample session looks like the following: Welcome tothe Calculator program. Please enter two integers separated by aspace: 10 20 Please enter an operator (+, -, *, /): + 10 + 20 =30.00 Do you want to continue?

Press Y for Yes and N for No: N Goodbye! Try to enter real numberswhen you are prompted for two integers. Check what happens. Can youfigure out why?

Explanation / Answer

please rate - thanks before change     please noteuse of casting for division and needing to get rid of enter ininput buffer (trash) This is probably what is being referred to inpart 2 #include                #include #include             intmain()                        {          char choice =0,yesno='Y',trash;          int var1 = 0, var2= 0;          double result =0; while(toupper(yesno)=='Y')        {          printf("Pleasechoose an option by entering the symbol of the operstion you wishto use. ");          printf("+Addition - Subtraction / Division * Multiplication %%Modulus ");          scanf("%c",&choice);                    printf("Pleaseenter the 2 integers: ");          scanf("%d %d",& var1,& var2);         scanf("%c",&trash);          switch(choice) { case '+': result = var1 + var2;           break; case '-': result = var1 - var2;           break; case '/': if(var2==0)               { printf("Illegal division by zero-result will be set to 0 ");                result=0;                }           else                result = var1 / (double)var2;     //note to getreal division           break; case '*': result = var1 * var2;           break; case '%': result = var1 % var2;          break;                                      default: printf("You did not choose an acceptable option-resultwill be set to 0 ");          result=0;           }           printf("%4d%3c %4d = %8.2f ",var1,choice,var2,result);                    printf("Doyou want to continue (y/n)?");          scanf("%c",&yesno);           //          scanf("%c",&trash);           } printf("Goodbye")          getch();                 return0;                   }
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