我更新了我的计算器代码,并添加了一个指数函数。然而,当我试图得到等式的答案时,我得到了这个错误:(lldb)任何帮助将不胜感激,因为这是我使用 C++ 的第一天!是的,仅此而已!这是我的代码!
#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, the first number of the calculator, the operator, and second number. Addition, Substraction, Multiplication, Division
cout<<"______________________________________________\n";
cout<<"|Welcome to The ExpCalc! Do you want to do |\n";
cout<<"|Exponent Math, or Basic Math(+, -, X, %) |\n";
cout<<"|Type in 'B' for basic Math, and'E' for |\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 your first integer!\n";
cin>> int1;
cout<<"Great! Now Enter your Operation: ex. *, /, +, -...\n";
cin>> oper;
cout<<"Now all we need is the 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 for Using The ExpCalc!\n";
}else if(typeOfMath == "Exp" ||typeOfMath == "E" ||typeOfMath == "e" ||typeOfMath == "Exponent"){
cout<<"Enter the desired Base. Example: 2^3, where 2 is the base.\n";
cin>> a;
cout<<"Now what is the desired exponent/power of the base? Ex. 2^3 where 3 is the exponent!\n";
cin>>b;
answerExponent = (pow(a,b));
cout<< answerExponent;
} else(cout<<"Wrong String!");
}
请帮忙!我可能也会问很多问题,所以请不要生气!我也在使用 Xcode 4 的 Mac 上!