Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I can only get the addition operation to display. What\'s wrong with my code? #i

ID: 440808 • Letter: I

Question

I can only get the addition operation to display. What's wrong with my code? #include using namespace std; int main() { int number1; int number2; cout << "Enter first number: " << endl; cin >> number1; cout << "Enter second number: " << endl; cin >> number2; cout << "Pick a mathematical operation: " << endl; cout << "1 - Addition(+)" << endl; cout << "2 - Subtraction(-)" << endl; cout << "3 - Multiplication(*)" << endl; cout << "4 - Division(/)" << endl; int choice; cout << "Choice: "; cin >> choice; switch (choice) { case 1: cout << "You picked Addition: " << (number1 + number2 << endl; break; case 2: cout << "You picked Subtraction: " << (number1 - number2 << endl; break; case 3: cout << "You picked Multiplication: " << (number1 * number2 << endl; break; case 4: cout << "You picked Division: " << (number1 / number2 << endl; break; default: cout << "You made an illegal choice" << endl; } return 0; }

Explanation / Answer

hi , try adding this code around your input 1 2 3 4 5 6 7 8 9 tempChar = cin.peek(); cin >> fun; //Sets user input to the variable Sel. if (tempChar == 's') { cin.clear(); cin.ignore(1); fun = 5; //or do code here } and add the tempChar like this 1 2 3 bool done = false; char choice; char tempChar; //add this line

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote