c++ - Simple calculator issues (Not outputting answers) -
just started reading c++ book , 1 of practice problems write small calculator takes input 1 of 4 arithmetic operations, 2 arguments operations, , prints out results.
sadly, program works until user inputs arithmetic option. if chose multiplication, id write "multiplication" , stay there , not after. image of problem im having
#include <iostream> #include <string> using namespace std; int main(){ // simple calculator program // declaring 3 variables float numberone; float numbertwo; string operationoption; // asking user 2 numbers he/she use cout << "enter first number apply arithmetic operation to: "; cin >> numberone; cin.ignore(); cout << "now enter second number: "; cin >> numbertwo; cin.ignore(); // using cin input users selection cout << "enter operation want perform." << endl; cout << "the options have are: " << endl; cout << "multiplication, subraction, division , addition: " << endl; cin >> operationoption; cin.ignore(); cin.get(); // happens if ( operationoption == "multiplication" ) { cout << "the first number multiplied second number is: " << numberone * numbertwo << endl; } else if ( operationoption == "division" ) { cout << "the first number divided second number is: " << numberone / numbertwo << endl; } else if ( operationoption == "subtraction" ) { cout << "the first number subtracted second number is: " << numberone - numbertwo << endl; } else if ( operationoption == "addition ") { cout << "the first number added second number is: " << numberone + numbertwo << endl; } else { cout << "you entered invalid option."; }; }
remove line :
cin.get();
will solve problem
Comments
Post a Comment