Question

In this lab you will code a simple calculator. It need not be anything overly fancy, but it is up to you to take it as far as

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new C++ program with name "main.cpp" is created, which contains following code.

main.cpp :

//Progarm to do arithmetic operation in C++
#include <iostream>
using namespace std;
//main method
int main()
{
//declaring variables
float runningTotal=0,n;
int number;
bool flag=true;
//using while loop
while(flag)
{
//showing menu system
cout<<"1.Enter 1 to add a number to total"<<endl;
cout<<"2.Enter 2 to subtract a number from total"<<endl;
cout<<"3.Enter 3 to multiply a number by total"<<endl;
cout<<"4.Enter 4 to divide a total by number"<<endl;
cout<<"5.Enter 0 to Exit program"<<endl;
//reading user input
cin>>number;
//passing number to switch case
switch(number)
{
//exit case
case 0:flag=false;
break;
//addition
case 1:cout<<"Enter number"<<endl;
cin>>n;
//add number and display total
runningTotal=runningTotal+n;
cout<<"Total : "<<runningTotal<<endl;
break;
//subtraction
case 2:cout<<"Enter number"<<endl;
cin>>n;
//subtract number and display total
runningTotal=runningTotal-n;
cout<<"Total : "<<runningTotal<<endl;
break;
//multiplication
case 3:cout<<"Enter number"<<endl;
cin>>n;
//multiply number and display total
runningTotal=runningTotal*n;
cout<<"Total : "<<runningTotal<<endl;
break;
case 4:cout<<"Enter number"<<endl;
cin>>n;
//divide number and display total
runningTotal=runningTotal/n;
cout<<"Total : "<<runningTotal<<endl;
break;
default:cout<<"Enter valid number"<<endl;
break;
}
}

return 0;
}

======================================================

Output : Compile and Run above program , will get the screen as shown below

Screen 1 :Screen showing menu

input 1.Enter 1 to add a number to total 2.Enter 2 to subtract a number from total 3.Enter 3 umber by total 4.Enter 4 to divi

Screen 2:Screen showing run1

input 1.Enter 1 to add a number to total 2.Enter 2 to subtract a number from total 3.Enter 3 to multiply a number by total 4.

1.Enter 1 to add a number to tota 2. Enter 2 to subtract a number from total 3.Enter 3 to multiply a number by total 4. Enter

Screen 3 :Screen showing run 3

input 1.Enter 1 to add a number to total 2.Enter 2 to subtract a number from total 3. Enter 3 to multiply a number by total 4

1.Enter 1 to add a number to total 2.Enter 2 to subtract 3.Enter 3 to multiply a number by total 4. Enter 4 to divide a total

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
In this lab you will code a simple calculator. It need not be anything overly fancy,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Creating a Calculator Program

    Design a calculator program that will add, subtract, multiply, or divide two numbers input by a user.Your program should contain the following:-The main menu of your program is to continue to prompt the user for an arithmetic choice until the user enters a sentinel value to quit the calculatorprogram.-When the user chooses an arithmetic operation (i.e. addition) the operation is to continue to be performed (i.e. prompting the user for each number, displayingthe result, prompting the user to add two...

  • The matrix operations that you should include are Addition, Subtraction and Multiplication. The driver can be...

    The matrix operations that you should include are Addition, Subtraction and Multiplication. The driver can be as simple as asking the user to enter two matrices and then presenting a simple menu that allows the user to select the operation they want to test. Have the menu in a loop so that the user can test any other operation unless they choose to exit the menu. Also, provide the user an option to select two new matrices. Make sure that...

  • Write a C++ Program that simulates a basic calculator using functions which performs the operations of...

    Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero) Display a menu for list of operations that can be calculated and get the input from user about his choice of calculation. Based on user choice of operation, take the input of number/numbers from user. Assume all input values are of type double. Calculations must be...

  • Write a C++ Program that simulates a basic calculator using functions which performs the operations of...

    Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero) Display a menu for the list of operations that can be calculated and get the input from the user about his choice of calculation. Based on user choice of operation, take the input of number/numbers from user. Assume all input values are of type double. Calculations...

  • Write a Python Program that displays repeatedly a menu as shown in the sample run below....

    Write a Python Program that displays repeatedly a menu as shown in the sample run below. The user will enter 1, 2, 3, 4 or 5 for choosing addition, substation, multiplication, division or exit respectively. Then the user will be asked to enter the two numbers and the result for the operation selected will be displayed. After an operation is finished and output is displayed the menu is redisplayed, you may choose another operation or enter 5 to exit the...

  • IN JAVA: Write a program that displays a menu as shown in the sample run. You...

    IN JAVA: Write a program that displays a menu as shown in the sample run. You can enter 1, 2, 3, or 4 for choosing an addition, subtraction, multiplication, or division test. After a test is finished, the menu is redisplayed. You may choose another test or enter 5 to exit the system. Each test generates two random single-digit numbers to form a question for addition, subtraction, multiplication, or division. For a subtraction such as number1 – number2, number1 is...

  • This is a quick little assignment I have to do, but I missed alot of class...

    This is a quick little assignment I have to do, but I missed alot of class due to the Hurricane and no one here knows what theyre doing. please help! this is Java with intelli-J Overview In this project students will build a four-function one-run calculator on the command line. The program will first prompt the user for two numbers, then display a menu with five operations. It will allow the user to select an option by reading input using...

  • Mini Project You are required to do this assignment on your own skills. No copying from...

    Mini Project You are required to do this assignment on your own skills. No copying from other students are not allowed. Write a menu driven Bash script using the guidelines given below. Some of the commands and syntax may not be covered in lectures. Please refer other sources to understand syntax and commands you need to complete this assignment. This program takes user input and to perform simple arithmetic operations such as addition, subtraction, multiplication and division of any two...

  • .Need code for my java class !! Write a simple java program that uses loops. You...

    .Need code for my java class !! Write a simple java program that uses loops. You may use ‘WHILE’ or ‘FOR’ or ‘DO-WHILE’ – you decide. The program should use a loop to compute the semester average for up to 5 students. In the loop the user will ask for a student name and their 3 test scores and add them up and divide the total by 3 giving the semester average. You will print out the student name and...

  • Header file for the Rational class: #ifndef RATIONAL_H #define RATIONAL_H class Rational { public: Rational( int...

    Header file for the Rational class: #ifndef RATIONAL_H #define RATIONAL_H class Rational { public: Rational( int = 0, int = 1 ); // default constructor Rational addition( const Rational & ) const; // function addition Rational subtraction( const Rational & ) const; // function subtraction Rational multiplication( const Rational & ) const; // function multi. Rational division( const Rational & ) const; // function division void printRational () const; // print rational format void printRationalAsDouble() const; // print rational as...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT