LLDB Error with Exponents on C++ -
i have updated calculator code, , adding exponent function. however, when try answer equation, error: (lldb) appreciated, first day c++! yep, that's all! here's code!
#include <math.h> #include <iostream> int int1, int2, answer; bool bvalue(true); std::string oper; std::string cont; using namespace std; std::string typeofmath; int a; int 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" || typeofmath == "basic" || typeofmath == "b" || typeofmath =="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" ||typeofmath == "e" ||typeofmath == "e" ||typeofmath == "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 = (pow(a,b)); cout<< answerexponent; } else(cout<<"wrong string!"); }
please help! ask lot of questions aswell, please dont mad! on mac, using xcode 4!
add line includes:
#include <string>
with done, able code compile , run correct output 2^3, in both visual studio, , in gcc 4.7.2 using ideone.com (click here see output). however, compiler still emits warning because of conversion double
int
should attend casting. change this:
answerexponent = (pow(a,b));
to this:
answerexponent = static_cast<int>(pow(a,b));
with said, compiler emitting warning reason, , casting telling compiler "shut , anyway". better approach avoid need cast. instead of doing above change, change line:
int answerexponent;
to this:
double answerexponent;
this makes more sense, because there little point in calling pow
double
s arguments if going throw away fractional part of number afterwards.
Comments
Post a Comment