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
		case '-';
		total = value1 + value2; // subtraction statement
		cout << "difference is: " << total << endl; //outputs differnce
		case '/';
		total = value1 + value2; // division statement
		cout << "quotient is: " << total << endl; //outputs quotient

		case '%';
		total = value1 + value2; // percentage statement
		cout << "modulus is: " << total << endl; //outputs modulus

		case '*';
		total = value1 + value2; // multiplication statement
		cout << "Product is: " << total << endl; //outputs product

		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

Can someone check my code please and check to see if my code is ok.


1) Did the program run correctly for all the values you tried?
2) Did you do all the points in the assignment?

If the answer is YES to both, then it's OK. If the answer is NO to either, then there's nothing for us to check, you need to check to see what you didn't do correctly.

If you need actual help with something, you have to explain in detail what you need help with.

Calc did not work need. Need to add static cast but not sure where it goes or how to do that. Thanks anyone that can help!!!

-- Can I suggest that you test your code with 10-6 which should give 4 but doesn't.

When you have fixed that problem in the obvious way, you can test

-- Then test your code with 5 2 /

This will highlight another error.

Ok, so I ran my calculator and went into an infinite loop and I am not sure how to fix this issue. Very lost and I am still learning C++ so not sure how to or where to start. Any help please would be greatly appreciated.

Have you changed your code?
If yes, do we know what it looks like now?
If no, can we really make any suggestions?
Think about it.

If I knew what to do I would not posting here. Any help would be greatly appreciated, this is y we post in here to get help. I am new to c++ and still trying to figure this out.

commented: I said "think" :icon_rolleyes: -4

If I knew what to do I would not posting here.

What Walt meant is that if you don't show us your updated code, it's rather difficult to help you with the changes you made.

thats just it I need to insert a static_cast and I don't know where to put it. It keeps going into an infinite loop

and I don't know how to fix it, please help this is due today

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.