c++ - Not Detecting Input Properly -
i've started c++ today, , working on advanced text-based calculator. anyways, i'm working on exponents, when start program, , enter string starts exponent mode, doesn't go expponent mode, regular calculator mode. here code:
// // main.cpp // c++ calculator // basic calculator application run through command line. // v.0.02 - second version of calculator, basic text, command line interface, loop. // created johnny carveth on 2013-04-17. // copyright (c) 2013 johnny carveth. rights reserved. // #include <math.h> #include <iostream> int int1, int2, answer; bool bvalue(true); std::string oper; std::string cont; using namespace std; std::string typeofmath; double a; double b; int answerexponent; int main(int argc, const char * argv[]) { // taking user input, first number of calculator, operator, , second number. addition, substraction, multiplication, division cout<<"______________________________________________\n"; cout<<"|welcome expcalc! want |\n"; cout<<"|exponent math, or basic math(+, -, x, %) |\n"; cout<<"|type in 'b' basic math, and'e' |\n"; cout<<"|exponential math! enjoy! (c) john l. carveth|\n"; cout<<"|____________________________________________|\n"; cin>> typeofmath; if(typeofmath == "basic" || "basic" || "b" || "b") { cout << "hello! please type in first integer!\n"; cin>> int1; cout<<"great! enter operation: ex. *, /, +, -...\n"; cin>> oper; cout<<"now need last int!\n"; cin>> int2; if (oper == "+") { answer = int1 + int2; } if (oper == "-") { answer = int1 - int2; }if (oper == "*") { answer = int1 * int2; }if (oper == "/") { answer = int1 / int2; } cout<<answer << "\n"; cout<<"thanks using expcalc!\n"; }else if(typeofmath == "exp" || "e" || "e" || "exponent"){ cout<<"enter desired base. example: 2^3, 2 base.\n"; cin>> a; cout<<"now desired exponent/power of base? ex. 2^3 3 exponent!\n"; cin>>b; answerexponent = double (pow(a,b)); } else(cout<<"wrong string!"); }
helpful tips only, remember first day c++. if of help, i'm using xcode 4!
you may want @ if expression
if(typeofmath == "basic" || "basic" || "b" || "b")
each thing between || evaluated conditional. try like:
if(typeofmath == "basic" || typeofmath == "basic" || typeofmath == "b" || typeofmath =="b") { // basic
make same modifications else if(typeofmath == "exp" || "e" || "e" || "exponent")
Comments
Post a Comment