Not sure if its my compiler or if its the code but Help

So anyways i'm not sure if its the code or the compiler that's messed up, and i see no problem with the code itself, the code is below:

#include <iostream>
#include <string>

using namespace std;

int main()
{
int number[3];
string = answer;

cout<<"Welcome To The Basic Calculator Program\n";
cout<<"Please Enter a Number";
cin>>number[1];
cout<<"Now Enter a Command: Add, Subtract, Divide, Multiply";
cin>>answer;
cout<<"Now Enter A Second Number To Perform The Computation";
cin>>number[2];

if(answer == "Add"||answer == "add")
{
number[3] = number[1] + number[2];
cout<<"\n\n"<<number[1]<<" Added To "<<number[2]<<" Is Equal To "<< number[3];


}

}

I think its right to the best of my knowledge but when i compile it, i get errors

any help is appreciated.
Last edited on
 
string = answer;


string has no variable name associated with it, and a answer is never declared. I don't see why the = sign is there. Seems like it'd work if you just removed that.

Also your function isn't returning anything. Put return 0; right before your last closing brace.

Edit: Oh, you still have a major problem with your array. You're using number[1] to try to access the first element, but that actually accesses the 2nd element. Similarly, number[3] will try to access the 4th element, but there are only 3 elements allocated for this array, so that will cause a problem. Just decrease the index by 1 every time you're using your array, and that should take care of it.
Last edited on
Ok thanks for your help, can't believe i didn't see that. Thanks for your time.
Topic archived. No new replies allowed.