1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
salantis [7]
4 years ago
6

Write a calculator program that keep reading operations and double numbers from user, and print the result based on the chosen o

peration using while loop. The loop must stop if the user enters Q letter.
NOTE: no need to write two classes.

Typical run of the program:

Enter an operation(+,-,*,/), Q to quit: +

Enter your first number: 6

Enter your second number: 5

Result= 11.0

Enter an operation(+,-,*,/), Q to quit: *

Enter your first number: 5

Enter your second number: 5

Result= 25.0

Enter an operation(+,-,*,/), Q to quit: q

You calculator has been ended!
Computers and Technology
1 answer:
AveGali [126]4 years ago
5 0

Answer:

 #include <iostream>

using namespace std;

int main()

{

   char opt;

   double num1,num2;

   cout<<"Enter an operation(+,-,*,/), Q to quit: ";

   cin>>opt;

  while(opt != 'Q'){

      cout<<"\nEnter your first number: ";

      cin>>num1;

      cout<<"\nEnter your second number: ";

      cin>>num2;

      if(opt == '+'){

          cout<<"Result = "<<num1+num2<<endl;

      }else if(opt == '-'){

           cout<<"Result = "<<num1-num2<<endl;

      }else if(opt == '*'){

           cout<<"Result = "<<num1*num2<<endl;

      }else if(opt == '/'){

           cout<<"Result = "<<num1/num2<<endl;

      }

      cout<<"Enter an operation(+,-,*,/), Q to quit: ";

      cin>>opt;

  }

  return 0;

}

Explanation:

First, include the library iostream, it allows to use the input/output instruction.

Create the main function and declare the variables.

Then print the message on the screen using cout instruction.

cin instruction is used to store the value into the variable.

then, take a while and check the condition if the value enters by the user is 'Q' or not. if true then enter the while otherwise exit.

after that, store the number enter by the user in the variables and then take the if-else statement for matching the operation enter by the user if match true then do the match operation.

This process continues until the user enters the value 'Q'.

if the user enters the 'Q'  then condition false and exit the program.

You might be interested in
Suppose you send data to the 11111111 11111111 11111111 11111111 ip address on an ipv4 network. to which device(s) are you trans
xenn [34]
All devices on your network segment.
4 0
3 years ago
A person who wants to buy a compact disc (cd) has just enough money to buy one, and chooses cd a instead of cd
bulgar [2K]

If someone who wants to acquire a compact disc (CD) has just sufficient money to buy one, and chooses CD a instead of CD b, then CD B is the opportunity cost.

 

To add, opportunity cost. <span>the loss of potential gain from other alternatives when one alternative is chosen.</span>

7 0
3 years ago
Read 2 more answers
Jenny wants to create a résumé after a two-years gap. What should she consider?
gavmur [86]

She should consider jail time.

3 0
3 years ago
Read 2 more answers
Sizing handles are used in Microsoft® Word® to _____.
Kamila [148]
<span>Sizing handles are used in Microsoft Word to resize an object.</span>
8 0
3 years ago
Hello I am currently working on a multi-sim project. In the file I have already created a timer that goes from 00 - 80 and reset
Digiron [165]

// Copyright 2017 The Chromium Authors. All rights reserved.

// Use of this source code is governed by a BSD-style license that can be

// found in the LICENSE file.

'use strict';

/**

* Alias for document.getElementById.

* @param {string} id The ID of the element to find.

* @return {HTMLElement} The found element or null if not found.

*/

function $(id) {

 // eslint-disable-next-line no-restricted-properties

 return document.getElementById(id);

}

/**

* Get the preferred language for UI localization. Represents Chrome's UI

4 0
3 years ago
Other questions:
  • Which symbol is used to separate a worksheet name from a cell reference?
    10·1 answer
  • You've been asked to find the largest number in a range of numbers. Which of the following could you use to find the largest num
    8·1 answer
  • Google Ads was designed to deliver three things to every advertiser: relevance, control, and results. It provides relevance by c
    11·1 answer
  • Ecommerce sites sell this to generate income
    11·1 answer
  • Using the __________ option, you can change the state of a model back to where a particular feature or features weren`t yet crea
    7·1 answer
  • Around what time did the Internet come around and how did it all start? Would like to know more of the history of how the intern
    12·1 answer
  • A store owner keeps a record of daily transactions in a text file. Each line contains three items: The invoice number, the cash
    7·1 answer
  • What is collaboration
    14·1 answer
  • write the definition of a class clock. the class has no constructors and one instance variable of type int called hours.
    12·1 answer
  • A system engineer enhances the security of a network by adding firewalls to both the external network and the internal company n
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!