Ok, I worked on my code so that I can repost it here.
This is what it has to do. I also need a static cast which I am not sure where to put it. Thanks for any help!!!!
Users should enter each number at an input prompt, then enter the operand at a third input prompt. The application should then display the result of the desired calculation and display a prompt asking the user whether the application should continue. If the user enters either an uppercase or lowercase y, the application should prompt the user for the next calculation. If the user enters either an uppercase or lowercase n, the application should exit.
1. Replacing the nested if... else statements with a switch statement. The application you created in Exercise 7.17 contained nested if... else statements to perform a calculation and display the result according to the value of the character that the user entered at the Enter operator: prompt. The controlling expression for the switch statement should contain the value of this character, char variable operation. Provide case labels for operators +, , *, / and %. Include a default case that displays an error message if none of the five operators was entered.
2. Modifying the Enter operator: prompt. Modify the Enter operator: prompt so that it displays the updated list of operators that the user can enter. Make sure to display blank lines where appropriate for readability.
3. Save, compile and run the completed application. Test the application to ensure that it runs correctly. Use several different inputs, and make sure each result is correct.
4. Preventing division by zero and performing traditional division. Add code to prevent the application from dividing by zero. Also, use the static_ cast operator on the numerator in the division calculation to prevent the application from performing integer division and thereby truncating the result.
5. Close the Command Prompt window.
#include <iostream> // required to perform C++ stream I/O
using namespace std; // for accessing C++ Standard Library members
// function main begins program execution
int main()
{
//define variables
int value1; // stores first value required for calculation
int value2; // stores second variable required for calculation
char operation; // stores data required for operation
char response = 'y'; // operation variable storage
int total; //stores total of operations
while (response != 'n' && response != 'N') //if statement is not 'n' and not 'N'
{
cout << "\n"; // insert newline for readability
cout << "Enter first operand: "; //prompt user for input
cin >> value1; //user inputs first value
cout << "Enter second operand: "; //prompts user for more input
cin >> value2; //user inputs second value
cout << "Enter operator (+, -, /, %, or *): "; // prompts user for
math operator
cin >> operation;
switch (operation)
{
case '+';
total = value1 + value2; // addition statement
cout << "sum is: " << total << endl; //outputs sum
break;
case '-';
total = value1 + value2; // subtraction statement
cout << "difference is: " << total << endl; //outputs differnce
break;
case '/';
total = value1 + value2; // division statement
cout << "quotient is: " << total << endl; //outputs quotient
break;
case '%';
total = value1 + value2; // percentage statement
cout << "modulus is: " << total << endl; //outputs modulus
break;
case '*';
total = value1 + value2; // multiplication statement
cout << "Product is: " << total << endl; //outputs product
break;
default:
cout << "Improper operand. Enter * for multiplication and +
for addition."; //error statement
} // end of switch statement
cout << "\n Would you like to enter another set of values (y = yes, n = no)?";
cout << "\n"; // insert newline for readability
return 0; // indicate that program ended successfully
} // end function main