C++ switch Statement check user input value
#include <iostream> using namespace std; int main()// ww w.j a v a 2 s . c om { int opselect; double fnum, snum; cout << "Please type in two numbers: "; cin >> fnum >> snum; cout << "Enter a select code: "; cout << "\n 1 for addition"; cout << "\n 2 for multiplication"; cout << "\n 3 for division : "; cin >> opselect; switch (opselect) { case 1: cout << "The sum of the numbers entered is " << fnum+snum; break; case 2: cout << "The product of the numbers entered is " << fnum*snum; break; case 3: cout << "The first number divided by the second is " << fnum/snum; break; } // end of switch cout << endl; return 0; }