Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

And my code is #include stdafx.h #include using namespace std; void main() { double D1(0); double D2(0); double D3(0); char Operator; const bool T(true), F(false);

image

And my code is

#include "stdafx.h"

#include

using namespace std;

void main()

{

double D1(0);

double D2(0);

double D3(0);

char Operator;

const bool T(true), F(false);

do

{

cout << "Enter the first number:";

cin >> D1;

cout << "Please enter an operator (+ - * / or type X to exit or C to restart): " << endl;

cin >> Operator;

} while (Operator == 'C');

while (!F)

{

switch (Operator)

{

case '+':

cout << "Enter second number : ";

cin >> D2;

D3 = D1 + D2;

cout << D1 << " + " << D2 << " = " << D3 << endl;

T;

break;

case '-':

cout << "Enter second number : ";

cin >> D2;

D3 = D1 - D2;

cout << D1 << " - " << D1 << " = " << D3 << endl;

T;

break;

case '*':

cout << "Enter second number : ";

cin >> D2;

D3 = D1 * D2;

cout << D1 << " * " << D2 << " = " << D3 << endl;

T;

break;

case'/':

cout << "Enter second number : ";

cin >> D2;

if (D2 == 0)

{

cout << "Undefined answer(s). Enter new divisor.." << endl;

cin >> D2;

}

else D3 = D1 / D2;

cout << D1 << " / " << D2 << " = " << D3 << endl;

T;

break;

case 'C':

case 'c':

D1 = 0;

cout << " Enter first number ";

cin >> D1;

T;

break;

case 'X':

case 'x':

F;

exit(0);

break;

default:

F;

cout << "Invalid response " << Operator << " - Please enter a valid operation - Enter X to quit or enter C to clear" << endl;

}

}

D1 = D3;

cout << "Enter new operator" << endl;

}

Return operator is not working and letter C and X is not working

Please fix my problem.. Thank you

ASSIGNMENT: Modify Lab Five such that you use functions for each math calculation (Add, Subtract, Multiply, and Divide). Pass in parameters to each function for the values to use and the functions will return the result. Use a function to read in the numbers involved. These numbers will be doubles. Also write a function that reads in the operator and returns a boolean - true if the operator is valid, false if not valid. This function will have two parameters. First is a "C-type" string of characters containing the valid operators. The second is a reference parameter where the operator will be placed if the operator entered is valid.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

include using namespace std Function to check if the entered operator is valid bool isValidOperatorconst char operators char operatorChar cout Please ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Primer Plus

Authors: Stephen Prata

6th Edition

978-0321776402, 0321776402

More Books

Students also viewed these Programming questions

Question

Find dy/dx for the following functions. y COS X sin x + 1

Answered: 1 week ago

Question

What does the following preprocessor directive do? #include

Answered: 1 week ago

Question

71/2 % of what amount is $1.46?

Answered: 1 week ago

Question

12 3/4 % of what amount is $27.50?

Answered: 1 week ago

Question

$1.34 is what percent of $655?

Answered: 1 week ago