Question
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);
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 ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started